create variable from array actionscript 3

Posted by steve on Stack Overflow See other posts from Stack Overflow or by steve
Published on 2010-05-25T17:19:11Z Indexed on 2010/05/25 17:21 UTC
Read the original article Hit count: 122

Filed under:
|
|

I'm currently trying to make a dynamic menu via an array and a loop. So when someone clicks on the first item of the array, "menu_bag_mc" it will link to the content "menu_bag_mc_frame" (or some name that will be unique to this array) that is another movieclip that will load. Below is the code I have so far:

//right here, i need to make a variable that I can put in the "addchild" so that
//for every one of the list items clicked, it adds a movieclip child with
//the same name (such as menu_bag_mc from above) with "_frame" appended.
//I tried the next line out, but it doesn't really work.
var framevar:MovieClip = menuList[i] += "_frame";

function createContent(event:MouseEvent):void {
    if(MovieClip(root).currentFrame == 850) {
    while(MovieClip(root).numChildren > 1)
    {
        MovieClip(root).removeChild(MovieClip(root).getChildAt(MovieClip(root).numChildren - 1));
    }
//Here is where the variable would go, to add a child directly related
//to whichever array item was clicked (here, "framevar")
MovieClip(root).addChild (framevar);
MovieClip(root).addChild (closeBtn);
}
else {
MovieClip(root).addChild (framevar);
MovieClip(root).addChild (closeBtn);
MovieClip(root).gotoAndPlay(806);
}
} 

Is there a way to make a unique variable (whatever it is) from the array so that I can name a movieclip after it so it will load the new movieclip? Thanks

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about variables