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

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 :worried:
[/COLOR][/COLOR]