# Variables for function names

**URL:** <https://forum.kirupa.com/t/variables-for-function-names/96695>\
**Category:** Uncategorized\
**Created:** [December 12, 2003, 12:03pm UTC](https://forum.kirupa.com/t/variables-for-function-names/96695 "2003-12-12T12:03:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carixpig](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/carixpig/32/304_2.png) [@Carixpig](https://forum.kirupa.com/u/Carixpig)\
**Post date:** [December 12, 2003, 12:03pm UTC](https://forum.kirupa.com/t/variables-for-function-names/96695/1 "2003-12-12T12:03:37Z")

</div>

Good day,

Here is the project I’ve been working on:  
[http://www.margaretsplace.com.au/Assets/mda.html](http://www.margaretsplace.com.au/Assets/mda.html)

Currently, it’s overly big because my scripting is verbose and cumbersome.

I’ve created an array to hold 8 function names:

[AS]  
\_global.swatchFunction = [“dropAUL”, “dropAUR”, “dropALL”, “dropALR”, “dropBUL”, “dropBUR”, “dropBLL”, “dropBLR”]  
[/AS]

I have 8 buttons on the stage. Each button is supposed to change the function so that I can use the same scrolling thumbnail mc to load images into different placeholder mcs.

So I proposed to myself that each button would have:

[AS]  
on(release){  
functionName = swatchFunction[0];  
}  
[/AS]

I’ve created the 8 functions in the first frame, so all I’m trying to do is swap over the function name with the on(release) handler.

Basically, can I use a variable to call a function?

Any suggestions? Direction? Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 12:14pm UTC](https://forum.kirupa.com/t/variables-for-function-names/96695/2 "2003-12-12T12:14:49Z")

</div>

Huh ? Swatch the function name: what function ? You told us you have 8 names, and you want to swatch _the function_ …

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 12:41pm UTC](https://forum.kirupa.com/t/variables-for-function-names/96695/3 "2003-12-12T12:41:17Z")

</div>

Read this while looking at the project online. Each time you click a quarter of the bag, I need a new function to be activated by each scrolling swatch.

I’d hoped to do this by reassigning each swatch with a new function name each time I click on a different quarter.

So, each quarter would have:  
[AS]  
on(release){  
functionName = swatchFunction[n]  
//where n matches with the function I want to use for that quarter, pulling it from the array I created at the beginning  
}  
[/AS]

Each scrolling swatch has this:  
[AS]  
on(release){  
functionName();  
//hoping that functionName is filled by the value I gave it from clicking the quarter above  
}  
[/AS]

so depending on which quarter I have clicked, the swatch will perform a different function.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 12, 2003, 3:14pm UTC](https://forum.kirupa.com/t/variables-for-function-names/96695/4 "2003-12-12T15:14:52Z")

</div>

You can perfectly do that, but you must make sure that both handlers use the same variable. For example, use \_root:

```auto

on(release){
        _root.functionName = swatchFunction[n]
}

```

```auto

on(release){
_root.functionName();
}

```

Will work perfectly 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 13, 2003, 5:46am UTC](https://forum.kirupa.com/t/variables-for-function-names/96695/5 "2003-12-13T05:46:47Z")

</div>

Thanks again, always dependable.
