# How do you use a variable in a path to a MovieClip

**URL:** <https://forum.kirupa.com/t/how-do-you-use-a-variable-in-a-path-to-a-movieclip/308251>\
**Category:** flash\
**Created:** [April 20, 2010, 8:01am UTC](https://forum.kirupa.com/t/how-do-you-use-a-variable-in-a-path-to-a-movieclip/308251 "2010-04-20T08:01:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashrocket](https://avatars.discourse-cdn.com/v4/letter/f/3ab097/32.png) [@flashrocket](https://forum.kirupa.com/u/flashrocket)\
**Post date:** [April 20, 2010, 8:01am UTC](https://forum.kirupa.com/t/how-do-you-use-a-variable-in-a-path-to-a-movieclip/308251/1 "2010-04-20T08:01:50Z")

</div>

Hi,

I’d like some help on using a variable in a path to a MovieClip.

I have a menu with 4 tabs. When I click on one I want it to open and the previous one to close.

I’m storing the previous tab as a variable (\_previousTab) but am having trouble adding the variable to the path to the MovieClip of the previous tab. The error Flash gives me is:

[COLOR=Red]TypeError: Error #1010: A term is undefined and has no properties.  
at MenuRun/menuOpen()[/COLOR]

Here’s my code:

* * *

package  
{  
import flash.display.MovieClip;  
import flash.events.MouseEvent;  
//import flash.display.SimpleButton;

```
public class MenuRun extends MovieClip
{
    public function MenuRun()
    {
        addEventListener(MouseEvent.CLICK, menuOpen);
    }
    
    private static var[COLOR=Blue] _previousTab:String[/COLOR];
    
    public function menuOpen(event:MouseEvent):void
    {            
        if(name != _previousTab)
        {
            trace("New tab");
            gotoAndPlay(2);
            if(_previousTab != null)
            {
           MovieClip(this.parent).[COLOR=Red]mainframe[_previousTab][/COLOR].gotoAndPlay(21);
            _previousTab = name;
            }
        
        else
        {
            trace("Same tab");
        }
    }
}

```

}

* * *

If I replace [COLOR=Red]mainframe[\_previousTab] [COLOR=Black]with the name of the MovieClip it works fine. I’m thinking it’s something to do with the variable being a String perhaps??

Any help greatly appreciated 😟  
[/COLOR][/COLOR]
