![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
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 " + loadTarget + " has started."); } loadListener.onLoadProgress = function(loadTarget, bytesLoaded, bytesTotal) { var percentLoaded = bytesLoaded/bytesTotal * 100; trace("%" + percentLoaded + " 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.)
target_mc
.pBar
and, on the Parameters tab, select Manual from the Mode pop-up menu.// create both a MovieClipLoader object and a listener object myLoader = new MovieClipLoader(); myListener = new Object(); // add the MovieClipLoader callbacks to your listener object myListener.onLoadStart = function(clip) { // this event is triggered once, when the load startspBar
.label = "Now loading: " + clip; }; myListener.onLoadProgress = function(clip, bytesLoaded, bytesTotal) { var percentLoaded = int (100*(bytesLoaded/bytesTotal));pBar
.setProgress(bytesLoaded, bytesTotal); };myLoader.addListener(myListener); myLoader.loadClip("veryLargeFile.swf", target_mc);
For more information, see MovieClipLoader class.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |