PDA

View Full Version : Syntax Problem for Adding MovieClips Dynamically From the Library onto the Stage



MoOMoOMiLK
June 12th, 2008, 03:41 PM
Hi guys,

I am trying to use the addChild method to add a MovieClip from the library onto the stage. I have a set of MovieClips with classes named: Definition1, Definition2, and so on... up to Definition12.

What I am trying to do is to write a function so that depending on the function parameter (which is a random number generated from 1 to 12), it will load different MovieClips starting with "Definition" followed by the random number. I have something like this but the syntax is incorrect. Can someone please correct me on my syntax? Thanks!!


private function attachDefinition(random:uint):void {
var _definition:MovieClip = new ["Definition" + random.toString()];
this.addChild(_definition);
}

creatify
June 12th, 2008, 04:32 PM
look into getDefinitionByName()... in help (F1) - select AS 3.0, in the language and components reference > All Packages > flash.utils package > functions.

Hope this helps.

MoOMoOMiLK
June 13th, 2008, 05:53 PM
Works like a charm. Thanks!!!