Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Load MovieClip from Library to Empty MovieClip AS 3 Tutorial

This flash tutorial shows how to load a MovieClip from the Library to an Empty MovieClip on the Stage with Flash ActionScript.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous flash ActionScript tutorial, we showed how to load MovieClip from the library to the stage. In this flash tutorial, we first create an Empty MovieClip on the stage with ActionScript. Then we load an MovieClip from the Library to the Empty MovieClip with ActionScript.

The completed Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

/*
Preparation: Create Linkage for the MovieClip

STEP 1: Prepare MovieClip
You already prepared a MovieClip in the library
In this example, the name of the MovieClip is called "Tree"

 

STEP 2: Create Linkage
Select the "Tree" movieclip from the library window
Select "Linkage..." from the pop up window
The Linkage Properties window appear
Check the "Export for ActionScript"
Enter "Tree" in the Class field.

 

Preparation: Create an empty MovieClip

1. Select "Insert" from the menu.
2. Select "New Symbol" from the drop down menu
3. The "Create New Symbol" window pop up.
4. Enter "emptyMC" in the Name field. Select MovieClip.
5. Select "Scene"
6. Drag the "emptyMC" to a desired position on the stage (e.g. 150, 210)
7. Give a new instance name "emptyMC_mc" to this empty MovieClip
*/

 

// Create a new MovieClip
var myMovieClip:MovieClip = new Tree();

 

// Add the new MovieClip to the empty MovieClip
// so that we can see it.
emptyMC_mc.addChild(myMovieClip);

 

// Set the location if required
//emptyMC_mc.x = 250;
//emptyMC_mc.y = 210;

Download Flash Source File:

Flash Source File load-mc-2.fla

Using addChild() Method with Variables

Some visitors are always asking the same question: How to use addChild() with a variable?

Yes, Using addChild() method with variables provide more flexibility and sometimes shorten the codes. There are some ways to do that. The most strightforward and easy-to-understand way is shown as below:

A simple example is:

var myMovieClip:MovieClip = new Tree();
var load_mc:String = "myMovieClip";
emptyMC_mc.addChild(this[load_mc]);

A more typical example is:

var i:int;
i = 1;

var myMovieClip1:MovieClip = new Tree();
var load_mc:String = "myMovieClip" + i;
emptyMC_mc.addChild(this[load_mc]);

A even more typical example is:

var i:int;
i = 1;

var myMovieClip1:MovieClip = new Tree();
var load_mc:String = "myMovieClip" + i;

var containerMC:String = "mc_" + i;
this[containerMC].addChild(this[load_mc]);

Remarks:

This Flash ActionScript tutorial shows how to load MovieClip from the library to an empty Movieclip on the stage. Sometimes you may have some MovieClips in the Library. The next Flash ActionScript tutorial will show how to load a random MovieClip from the Library to an empty MovieClip on the stage.