Preloading external media
199
Preloading SWF and JPEG files
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. Using a MovieClipLoader object to preload SWF and JPEG files
involves the following steps:
Create a new MovieClipLoader object
You can use a single MovieClipLoader object to track
the download progress of multiple files, or create a separate object for each file’s progress.
var loader: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.
For example, the following code creates a generic listener object named
loadListener
, and
defines for itself
onLoadStart
,
onLoadProgress
, and
onLoadComplete
functions.
// Create listener object:
var loadListener:Object = new Object();
loadListener.onLoadStart = function (loadTarget) {
trace("Loading into " + load " has started.");
}
loadListener.onLoadProgress = function(loadTarget, bytesLoaded, bytesTotal) {
var percentLoaded = bytesLoaded/bytesTotal * 100;
trace("%" + percent " into target " + loadTarget);
}
loadListener.onLoadComplete = function(loadTarget) {
trace("Load completed into: " + loadTarget);
}
Register the listener object with the MovieClipLoader object
In order for the listener object
to receive the loading events, you must register it with the MovieClipLoader object.
loader.addListener(loadListener);
Begin loading the file (JPEG or SWF) into a target clip
To start the download of the JPEG or
SWF file, you use the
MovieClipLoader.loadClip()
method.
loader.loadClip("scene_2.swf");
Note:
You can use only MovieClipLoader methods to track the download progress of files loaded
with the
MovieClipLoader.loadClip()
method. You cannot use the
loadMovie()
function or
MovieClip.loadMovie()
method.
The following example uses the
setProgress()
method of the ProgressBar component to
display the download progress of a SWF file. (See “ProgressBar component” in Using
Components Help.)
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...