# Dynamically assigning functions to mcs onPress

**URL:** <https://forum.kirupa.com/t/dynamically-assigning-functions-to-mcs-onpress/239123>\
**Category:** flash\
**Created:** [September 18, 2007, 9:27pm UTC](https://forum.kirupa.com/t/dynamically-assigning-functions-to-mcs-onpress/239123 "2007-09-18T21:27:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hausnfranz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/hausnfranz/32/2427_2.png) [@Hausnfranz](https://forum.kirupa.com/u/Hausnfranz)\
**Post date:** [September 18, 2007, 9:27pm UTC](https://forum.kirupa.com/t/dynamically-assigning-functions-to-mcs-onpress/239123/1 "2007-09-18T21:27:34Z")

</div>

Hi all,

I am trying to work out the logistics/structure of writing general ‘action’ functions (ie, move, scale, etc) and then assigning those functions to different mcs depending on what is currently ‘in focus’.

Here is the code that illustrates my current thinking. It is general, and not specific! In kirupa style, I will highlight each line to express my thinking, so that you can better provide me with feedback.

```auto

function fadeOut(mc) {
    if ((mc).width >= 50) {
        --(mc)._width;
        --(mc)._height;
    } else {
        //DO NOTHING
    }
}

function fadeIn() {
}
function zoomIn() {
}
function zoomOut() {
}

onEnterFrame = function() {
    if (homeScreen == true) {
    btnDown.onPress = fadeOut(mc_home) = fadeIn(mc_contacts);
    } else if (contactsScreen == true) {
        btnDown.onPress = zoomIn(mc_people) = zoomOut(mc_numbers);
    }
}

```

This is an example of an action function that I want to work with mcs.

```auto

function fadeOut(mc) {
    if ((mc).width >= 50) {
        --(mc)._width;
        --(mc)._height;
    } else {
        //DO NOTHING
    }
}

```

Is this how I get it to [COLOR=Red]receive an mc?[/COLOR]

```auto

function fadeOut[COLOR=Red]**(mc)**[/COLOR] {

```

And how do I reference the mc afterwards, [COLOR=Red]like this?[/COLOR]

```auto

function fadeOut[COLOR=Red](mc)[/COLOR] {
     if ([COLOR=Red](mc)[/COLOR].width >= 50) {

```

More action functions, to be filled in later.

```auto

function fadeIn() {
}
function zoomIn() {
}
function zoomOut() {
}

```

Here is how I am checking for button presses. Seems pretty straight forward.

```auto

onEnterFrame = function() {

```

Here is how I am checking to see what is ‘in focus’.

```auto

    if (homeScreen == true) {

```

Here is where I am also confused, how do I get an mc to work with the action functions? Can I have two functions working on one mc at the same time? Is this even the right ‘[COLOR=Red]high level’ structure[/COLOR] that I should be using for this task, let alone [COLOR=DarkOrange]correct syntax?[/COLOR]

```auto

    [COLOR=Red]btnDown.onPress = fadeOut(mc_home)[/COLOR][COLOR=DarkOrange] = fadeIn(mc_contacts);[/COLOR]

```

This is the same as the above code, just working with different functions and mcs.

```auto

    } else if (contactsScreen == true) {
        btnDown.onPress = zoomIn(mc_people) = zoomOut(mc_numbers);
    }
}

```

I will potentially have close to 50 mcs that I will have to work with, and maybe 20 ‘action’ functions. So I wanted to make sure that I have the basics down, then I can just rinse and repeat. Anything else I am not considering?

Thanks to anyone who can lend some clarity,

Nick
