I am wondering how to add a MovieClip from the library onto the stage programmatically.
How would I go about doing this?
Symbols within Flash may define ActionScript Linkage.
AS Linkage may be set by right-clicking a symbol from the library and selecting Properties...
Check Export for ActionScript and enter a Class name.
If you don't need to explicitly define a base class beyond the symbol type, you can enter AS Linkage directly from the Library:
This creates a class definition no different than if you had written an ActionScript class.
Create instances by instantiating new instances of your AS Linkage type:
var symbolExample:SymbolExample = new SymbolExample();
addChild(symbolExample);
You will essentially be creating a "class" for your movieclip. Do what James suggests above... But when calling it into your program you will have to execute something like this:
//instantiate your object
var movieClip:MovieClip = new MovieClip;
//add it to the stage
addChild(movieClip);
//object will default to x=0 , y=0 so you can define that as well
movieClip.x=100;
movieClip.y=100;
//and so on...
movieClip
is whatever you want... but MovieClip
is the name you assign the class in the properties dialog. These var/class relationships are typically case sensitive so follow this formula for anything you create in your library.
There are many different ways to call and remove your objects, and it can get simpler or more complicated depending on what you intend to do with your object. For instance, you can tell the object which layer to occupy with:
addChildAt(movieClip, 1);
this adds movieClip
to layer 1 or the layer just above the bottom-most layer.
Hope this helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With