Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a MovieClip from the library to the stage programmatically?

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

How would I go about doing this?

like image 876
user1798964 Avatar asked Nov 13 '12 00:11

user1798964


2 Answers

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);
like image 87
Jason Sturges Avatar answered Sep 28 '22 02:09

Jason Sturges


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

like image 38
MaxG Avatar answered Sep 28 '22 01:09

MaxG