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 file’s
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: " + err " [" + "]");
};
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: " + tar " is " + numPercent "%
loaded");
};
mclListener.onLoadComplete = function(target_mc:MovieClip,
status:Number):Void {
trace("onLoadComplete: " + target_mc);
};
NO
T
E
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.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...