Scott
Scott

Reputation: 3967

AS3 add movie clip to stage using variable which holds the MC name

I know how to add a movie clip to the stage from the library but i'm strugling to do it when the I need to load a movie clip from the library when the name of the movie clip is held in a variable.

for(var i:Number = 0; i < 64; i++)
{
    var blueIconS:blueIcon = new blueIcon();
    addChild(blueIconS);
    blueIconS.x = 100;
    blueIconS.y = 100;
}

The above code works for adding the blueIcon but I have a variable in that loop which tells which icon to load.

sectorsMCs[jewelsIDs[i]]

The above will tell me what MC name to load but how do I load a MC from library by that variable value?

Upvotes: 1

Views: 3649

Answers (1)

PatrickS
PatrickS

Reputation: 9572

You may have to link your MovieClip to a specific class for the following to work...

 var mcName:String = sectorsMCs[jewelsIDs[i]];
 var ClassName:Object = getDefinitionByName(mcName);
 var mc:MovieClip = new ClassName();

Upvotes: 1

Related Questions