EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 594

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
594 Working with Images, Sound, and Video
For more information about loading external SWF and image files, see About loading SWF
files and the root timeline” on page 597.
To preload SWF and JPEG files into movie clip instances, you can use the MovieClipLoader
class. This class provides an event listener mechanism to give notification about the status of
file downloads into movie clips. To use a MovieClipLoader object to preload SWF and JPEG
files, you must complete the following:
Create a new MovieClipLoader object You can use a single MovieClipLoader object to
track the downloading progress of multiple files or create a separate object for each files
progress. Create a new movie clip, load your contents into it, then create the
MovieClipLoader object as shown in the following code:
this.createEmptyMovieClip("img_mc", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();
Create a listener object and create event handlers
The listener object can be any
ActionScript object, such as a generic Object object, a movie clip, or a custom component.
The following example creates a generic listener object named
loadListener and defines for
itself
onLoadError, onLoadStart, onLoadProgress, and onLoadComplete functions:
// Create listener object:
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String,
status:Number) {
trace("Error loading image: " + errorCode + " [" + status + "]");
};
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
trace("onLoadStart: " + target_mc);
};
mclListener.onLoadProgress = function(target_mc:MovieClip,
numBytesLoaded:Number, numBytesTotal:Number):Void {
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
trace("onLoadProgress: " + target_mc + " is " + numPercentLoaded + "%
loaded");
};
mclListener.onLoadComplete = function(target_mc:MovieClip,
status:Number):Void {
trace("onLoadComplete: " + target_mc);
};
NOTE
Flash Player 8 allows you to check the HTTP status of a MovieClipLoader download
within the onLoadComplete and onLoadError event listeners. This ability allows you to
check why the file was unable to download—whether it was a server error, or the file was
unable to be found, and so on.

Table of Contents

Related product manuals