February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Create dynamic instances of MovieClips in your Library using only AS3

Problem
You want to dynamically create instances of objects in your library and add them to stage.

Solution
Export your library item for ActionScript, give it a Class name and instantiate using the “new” keyword. Then use “addChild()” to add it to stage.

Detailed explanation
Please create movie clip what you want to put on the stage. Right click to this movie clip and use properties. In the properties box, set up your MovieClip so that it looks like this:

index11

Then, add the following code to the timeline:

var my_pic_mc:Pic = new Pic(); // creates a new version of your
MovieClip

addChild(my_pic_mc); // adds that version to the stage

In the end you will get this:
index21

Source:
display objects1

2 comments to Create dynamic instances of MovieClips in your Library using only AS3

  • rollee

    How can you dynamically make multiple instances of that mc, each having individual names? If your gonna use an array for that, how will you access that mc say through a function using the instance name…say

    functionName(instance name);

    thanks for any reply.

  • PauPawSan

    Wow! Thanks for this post, help me a lot.
    I was stumbling everywhere and finally found this post that you can attach your movie into a class so that you can dynamically create new instance of the class.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>