# Passing instance name to function as a variable

**URL:** https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848
**Category:** Uncategorized
**Created:** [April 25, 2006, 12:08am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848 "2006-04-25T00:08:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tsunchoo](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tsunchoo](https://forum.kirupa.com/u/tsunchoo)
#### Post date: [April 25, 2006, 12:08am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/1 "2006-04-25T00:08:11Z")

</div>

hello friends

the idea is that the site keeps tracks of whatever page is **current** and passes this variable to the **alpha function** which will target that movie instance to fade when moving to another page - then that page’s name will be assigned to **current**.

this is the code that i have now…

#include “alpha.as”  
evolution.onRelease = function() {  
this[current].gotoAndPlay(2);  
this[current].alpha(5, 0);  
};

**evolution** and **solo** exist in the same timeline…

the hierachy is like this there is a movie called **pictures** on the root timeline - this contains all the buttons and all the scripts that you see (except the external script for the alpha function) - plus the variable **current** is declared in it too.

it’s a one frame movie which contains another movie **solo** which is what i am trying to target when a button is clicked.

any help very much appreciated…

Si

:thumb2:

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 25, 2006, 12:14am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/2 "2006-04-25T00:14:15Z")

</div>

This would be my best guess but it would help if you posted some more code or even an FLA :cowboy:

```auto
#include "alpha.as"
evolution.onRelease = function() {
 this._parent[current].gotoAndPlay(2);
 this._parent[current].alpha(5, 0);
};

```

---

<div class="post-metadata">

### Author: ![tsunchoo](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tsunchoo](https://forum.kirupa.com/u/tsunchoo)
#### Post date: [April 25, 2006, 12:21am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/3 "2006-04-25T00:21:35Z")

</div>

wow that seems to have done it - jesus you wouldn’t believe how many friggin combinations of brackets and dots i have tried.

i even tried the target path thing - why the hell didn’t that come up with what you posted?

hmmmm.

another dumb question if my var is declared in the same frame as all this stuff is happening why doesn’t it keep reseting itself? or does it only run once - but not keep looping?

thanks for your help though - that was 2 days of buggering around…

Si

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 25, 2006, 12:25am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/4 "2006-04-25T00:25:21Z")

</div>

:lol: Glad to help :hoser:

If you declare a variable with the _var_ statement in a function, it is local to that function and is deleted after the function has executed - or is that not what you are asking?

---

<div class="post-metadata">

### Author: ![tsunchoo](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@tsunchoo](https://forum.kirupa.com/u/tsunchoo)
#### Post date: [April 25, 2006, 12:34am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/5 "2006-04-25T00:34:19Z")

</div>

not quite what i asked but still helpful…i think what i am asking is so blindingly obvious you missed it…

now i’ve put it into words i think my question is obsolete…

Si

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 25, 2006, 12:43am UTC](https://forum.kirupa.com/t/passing-instance-name-to-function-as-a-variable/186848/6 "2006-04-25T00:43:11Z")

</div>

Oooh after re-reading I think I got it. They aren’t reset because you only enter the frame once so the code is only executeD once. Unless you use a repetative action such as an onEnterFrame event, the code will only execute once 🙂
