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 Different MovieClip from Library to Empty MovieClip One by One AS 3 Tutorial (2)

In previous flash ActionScript tutorial, we show how to load different MovieClips from the Library to an Empty MovieClip on the Stage one by one with loop animation. The method seems simple, but actually a bit stupid. What if there are 10 or more different MovieClips in the Library? The timeline will be very long and the ActionScript codes need to be re-written again and again. Let's see if there is a better way to do it.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In this Flash ActionScript tutorial, the codes are much simpler than the previous method. All different MovieClips are loaded from the Library using the same timeline and codes. The length of timeline is the same even there are a lot of different MovieClip loading into the stage one by one.

The idea is very simple, we simply used a number to control which MovieClip from the Library is loaded into the empty MovieClip on the stage.

set Linkage of MovieClip

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

Flash ActionScript Codes (Frame 1):

// declare a new MovieClip
var myMovieClip:MovieClip;

 

// declare a number i
// It used to monitor which MovieClip to load
var i:Number;

 

/*
The trick is that when:
i = 1 load Tree MovieClip
i = 2 load Light House MovieClip
i = 3 load Plane MovieClip
*/

 

// Check if number i is null
// i is null when the MovieClip first starts up.
if (isNaN(i)) {

// set i to 1
i = 1;

// display message to visitor
output_txt.text = "The Tree MovieClip was added!";

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

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

} else if (i == 1) {

// display message to visitor
output_txt.text = "The Tree MovieClip was added!";

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

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

} else if (i == 2) {

// display message to visitor
output_txt.text = "The Light House MovieClip was added!";

// Create a new MovieClip
myMovieClip = new light_house();

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


} else if (i == 3) {

// display message to visitor
output_txt.text = "The Plane MovieClip was added!";

// Create a new MovieClip
myMovieClip = new Plane();

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

}

Then the loaded MovieClip was removed in frame 30 using the following Flash ActionScript codes:

// Remove the loaded MovieClip
emptyMC_mc.removeChild(myMovieClip);

And then use i to control which MovieClip need to load from the Library

// Use i to control loading the MovieClip
if (i == 1) {
i = 2;
} else if (i == 2) {
i = 3;
} else if (i == 3) {
i = 1;
}

Download Flash Source File:

Flash Source File load-mc-5.fla

Remarks:

This Flash ActionScript tutorial shows how to load different MovieClip from the library to an empty Movieclip on the stage one by one with a more clever method.