How to add MovieClip from the library to the scene programmatically?

I am wondering how to add MovieClip from a library to a scene programmatically.

How can I do it?

+7
source share
3 answers

Characters inside Flash can define ActionScript bindings.

AS Linkage can be installed by right-clicking on a symbol from the library and selecting "Properties" ...

symbol-properties

Check Export for ActionScript and enter the class name.

If you do not need to explicitly define the base class outside the character type, you can enter AS Linkage directly from the library:

library

This creates a class definition just as if you were writing an ActionScript class.

Create instances by creating new instances of type AS Linkage:

var symbolExample:SymbolExample = new SymbolExample(); addChild(symbolExample); 
+10
source

Essentially, you will create a “class” for your movie clip. Do what James suggests above ... But when calling into your program, you need to do 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 what you want ... but movieClip is the name you assign to the class in the properties dialog. These var / class relationships are usually case sensitive, so follow this formula for everything you create in your library.

There are many different ways to call and delete your objects, and this can become simpler or more complicated depending on what you are going to do with your object. For example, you can specify the object for which the layer will occupy:

 addChildAt(movieClip, 1); 

this adds movieClip to layer 1 or to a layer just above the bottommost layer.

Hope this helps ...

+3
source

You create your movie clip in any way convenient for you, and then when it is in the library, you right-click and select “Properties”, select the “Export for ActionScript” checkbox, select the class name and export it to frame 1. Then, when you want to add you add it like any other object. I am sure that someone will have a more detailed explanation after me, this is a general idea.

0
source

All Articles