In ActionScript 2.0 it is quite easy to import movie clips from Library via the MovieClip.attachMovie() function. In ActionScript 3.0 it’s a little bit different. The movie clips (or assets in the Library) don’t have a linkage id anymore. Instead they have class names.
So the way to import a movie clip (or another asset) is to first get a reference to that class specified as class name. This is done using the flash.utils.getDefinitionByName() function. Then instantiate the class and finally add the object to the display list.
Here is a simple example:
1 2 3 4 5 6 7 8 9 | import flash.utils.getDefinitionByName; var className:String = "TestClip"; var ClassReference:Class = getDefinitionByName(className) as Class; var clip:MovieClip = new ClassReference(); addChild(clip); clip.x = 100; clip.y = 100; |