Handy wee snippet:
Class(getDefinitionByName(getQualifiedClassName(myMC)))
(Remember to import flash.utils)
Then you can bang it out like-a-so:
var mc:MovieClip = new targetClass();
eg. this below, gets the class of an instance called ‘page0’ within contentMC, creates a new one and adds it to the stage:
var targetClass:Class = Class(getDefinitionByName(getQualifiedClassName(contentMC.page0))); var tempPage:DisplayObject = new targetClass(); addChild(tempPage);
And if you’re just after referencing a class in your library by a string or something for instance, you can use this:
var ClassReference:Class = getDefinitionByName(gameData.level[game.level].background.backgroundLayer) as Class; var bg = new ClassReference();
Tech Reference: AS3
Leave a Reply