Category: flash

Dynamic class names are neat

Author: seven October 4, 2007

Attaching movieclips to the stage in AS3 is easy. But what if we need to attach a movieclip with dynamically created name?
var page:MovieClip = new ["page"+i]; // won't work :)

But this will:
[ftf w=”490″ h=”130″]
var dynamicClass:String = “page” + i;
var classRef:Class = getDefinitionByName(dynamicClass) as Class;
var page:MovieClip = new classRef();
addChild(page);
[/ftf]

Author
seven
CEO/CTO at Nivas®
Neven Jacmenović has been passionately involved with computers since late 80s, the age of Atari and Commodore Amiga. As one of internet industry pioneers in Croatia, since 90s, he has been involved in making of many award winning, innovative and successful online projects. He is an experienced full stack web developer, analyst and system engineer. In his spare time, Neven is transforming retro-futuristic passion into various golang, Adobe Flash and JavaScript/WebGL projects.