# \[Flash CS3/AS2\] How can I use a variable as the instance name?

**URL:** <https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229>\
**Category:** flash\
**Created:** [June 4, 2008, 9:52am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229 "2008-06-04T09:52:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sugarfree](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sugarfree](https://forum.kirupa.com/u/sugarfree)\
**Post date:** [June 4, 2008, 9:52am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/1 "2008-06-04T09:52:10Z")

</div>

Hello all!,  
my first post here! I’ve visited Kirupa a lot, though, as it’s always been fairly straightforward and never overly technical - just what I like!

My problem is this.  
I have a static shopping centre floorplan with movieclips for each unit. There is also a list of the stores fed in from an XML page. When they rollover either the unit on the floorplan or the storename in the list, a little information panel appears for each store.  
All that’s fine.

The problem is I want the corresponding unit to highlight when the text is rolled over and vice versa, but just can’t seem to get it to work!!! You would think that would be the easy part.  
I have a variable - currentunit - which I pass from the onRollover. This is the same as the corresponding instance name of the floorplan unit.

I though I could use something like

**[currentunit]gotoAndPlay("\_over");**

but no success.  
I’d be grateful for your thoughts…

Ta

---

<div class="post-metadata">

**Author:** ![sugarfree](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sugarfree](https://forum.kirupa.com/u/sugarfree)\
**Post date:** [June 4, 2008, 10:16am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/2 "2008-06-04T10:16:58Z")

</div>

Oh,  
I think it’s a syntax thing - this seems to get me close to what I need.

\*\*\_root[currentunit].gotoAndPlay("\_over"); \*\*

---

<div class="post-metadata">

**Author:** ![doctorfeelyg](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@doctorfeelyg](https://forum.kirupa.com/u/doctorfeelyg)\
**Post date:** [June 4, 2008, 10:29am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/3 "2008-06-04T10:29:48Z")

</div>

Hi sugarfree,

I’d be interested to see your fla if possible, as am working on a something similar, a rollover map of london boroughs.

cheers

dfg

---

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [June 4, 2008, 10:41am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/4 "2008-06-04T10:41:32Z")

</div>

Yes it is, when targeting vars in the square brackets, it has to be appended with this or \_root or wherever it is, you can’t start a line with the square brackets.

HOwever the square brackets are usually used to target multiple variables in a loop, I don’t see why you need them at all here.

Doctor - an flv is a video file.

---

<div class="post-metadata">

**Author:** ![doctorfeelyg](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@doctorfeelyg](https://forum.kirupa.com/u/doctorfeelyg)\
**Post date:** [June 4, 2008, 10:53am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/5 "2008-06-04T10:53:24Z")

</div>

[quote=rumblesushi;2336331]  
Doctor - an flv is a video file.[/quote]

noted, thanks 😊

---

<div class="post-metadata">

**Author:** ![sugarfree](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sugarfree](https://forum.kirupa.com/u/sugarfree)\
**Post date:** [June 4, 2008, 10:56am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/6 "2008-06-04T10:56:05Z")

</div>

[quote=rumblesushi;2336331]Yes it is, when targeting vars in the square brackets, it has to be appended with this or \_root or wherever it is, you can’t start a line with the square brackets.

HOwever the square brackets are usually used to target multiple variables in a loop, I don’t see why you need them at all here.

Doctor - an flv is a video file.[/quote]

Hi,  
it doesn’t work when I don’t have the brackets.  
I guess, could it be cos my rollover function needs to ‘evaluate’ the currentunit variable?  
Either way, just glad it seems to work!

```auto
function btnOnRollover(){
 currentunit = this.unitid.text;
 _root[currentunit].gotoAndPlay("_over"); 
 
 //this.menubg.gotoAndPlay("_over") ;
 GetPage();
}   

```

---

<div class="post-metadata">

**Author:** ![sugarfree](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@sugarfree](https://forum.kirupa.com/u/sugarfree)\
**Post date:** [June 4, 2008, 10:58am UTC](https://forum.kirupa.com/t/flash-cs3-as2-how-can-i-use-a-variable-as-the-instance-name/262229/7 "2008-06-04T10:58:25Z")

</div>

[quote=doctorfeelyg;2336322]Hi sugarfree,

I’d be interested to see your fla if possible, as am working on a something similar, a rollover map of london boroughs.

cheers

dfg[/quote]

Hi,  
I’ve still to tidy it a fair bit. I’ll get back to you! :thumb2:
