7

I am wondering how to add a MovieClip from the library onto the stage programmatically.

How would I go about doing this?

12

Symbols within Flash may define ActionScript Linkage.

AS Linkage may be set by right-clicking a symbol from the library and selecting Properties...

symbol-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:

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);
| improve this answer | |
4

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...

| improve this answer | |
0

You create your movieclip via any method you want, then when it is in the library you right click and select Properties, check the box Export for Actionscript, choose a class name and export in frame 1. Then whenever you want to add it you add it as you would any other object. I'm sure someone else will have a more detailed explanation after me, this is the general idea.

| improve this answer | |
  • The term you are specifically after is Symbol Linkage – James McGrath Nov 13 '12 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.