User Guide

494 Chapter 6: Components Dictionary
Example
The following code creates a Loader instance and sets the autoload property to false so that the
loader must wait for a call to
load() to begin loading content. Next, the contentPath property
is set, which indicates where to load content from. Then other tasks can be performed before the
content is loaded with
loader.load().
createClassObject(mx.controls.Loader, "loader", 0);
loader.autoLoad = false;
loader.contentPath = "logo.swf";
// Perform other tasks here and *then* start loading the file.
loader.load();
Loader.percentLoaded
Availability
Flash Player 6 (6.0 79.0).
Edition
Flash MX 2004.
Usage
loaderInstance.percentLoaded
Description
Property (read-only); a number indicating what percent of the content has loaded. Typically, this
property is used to present the progress to the user in an easily readable form. Use the following
code to round the figure to the nearest integer:
Math.round(bytesLoaded/bytesTotal*100))
Example
The following example creates a Loader instance and then creates a listener object with a
progress handler that traces the percent loaded and sends it to the Output panel:
createClassObject(Loader, "loader", 0);
loadListener = new Object();
loadListener.progress = function(eventObj){
// eventObj.target is the component that generated the progress event,
// that is, the loader
trace("logo.swf is " + loader.percentLoaded + "% loaded."); // track loading
progress
}
loader.addEventListener("complete", loadListener);
loader.content = "logo.swf";