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

Flash AS Tutorial: Load External Image to Empty MovieClip (2)

Sometimes you have some external images loading to the same movieclip of Flash Movie. Then you should consider using a re-usable function.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In this Flash ActionScript tutorial, we use a more flexible or a more re-usable function to load the external image. This is useful if you have more than one external images to load to the same empty MovieClip (e.g. Photo Show). In this situation, the function can be re-used again.

The complete Flash Movie is shown as above, you may try how it works before you start this tutorial. A simple Text Preloader is also added to the loading progress.

Flash ActionScript Codes:

//Declare the loading percentage
var percent:Number;

//Declare a new loader with the name "loader" to use later
var loader:Loader;

//Load the external image
loadExternalImage("island.png");

 

function loadExternalImage(fileURL:String):void {

//Create a new Loader to load the image
loader = new Loader();

//Load the external image into the Loader
loader.load(new URLRequest(fileURL));

//Listen to the progress of the loading
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadingProgress);

// Listen when the loading of image is completed
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingComplete);

}

 

function loadingProgress(evt:ProgressEvent) {

//Calculate the loading percentage
percent = Math.round((evt.bytesLoaded/evt.bytesTotal) * 100);

//Display the loading percentage to visitors
//Actually you can use AS to add the TextField dynamically
percentLoaded_txt.text = "Loading picture.... " + String(percent) + "% loaded";

}

 

function loadingComplete(evt:Event) {

//Display the Loader on the MainTimeline
//The holder_mc (new symbol) was created before by:
/*
Insert -> New Symbol -> Select MovieClip
Give this new symbol any name you like (e.g. MyImage)
Return to the scene.
Drag the MovieClip (e.g. MyImage) into your scene from the Library window
Give the instance name of this MovieClip "holder_mc"
*/
holder_mc.addChild(loader);

//Hide the loading progress text that no longer in use
percentLoaded_txt.visible = false;

}

Download Flash Source File:

Flash Source File load-image-7.fla

Remarks:

This Flash ActionScript tutorial show how to use a more flexible and re-usable function to load external image.