Working with external data in Flash - MovieClipLoader class
(Page 4 of 6 )
The MovieClipLoader Class can be used in lieu of the loadMovie() method.
This class lets you implement listener call backs that provide status information while SWF or JPEG files are being loaded into movie clips.
Instead of using loadMovie()or MovieClip.loadMovie() methods, you need to use MovieClipLoader.loadClip() to use the features of the MovieClipLoader class.
The following events will take place in the order listed when you use MovieClipLoader Class:
MovieClipLoader.onLoadStart– This event listener will fire when the first bytes of the SWF or JPEG file are downloaded.
MovieClipLoader.onLoadProgress– This event listener will continuously fire during the loading process, and can be used to show the loading progress to the users. During the load process you can call MovieClipLoader.getProgress()at any time to know the progress of the loading.
MovieClipLoader.onLoadComplete– This event listener will fire when the entire file has been downloaded.
MovieClipLoader.onLoadInit– This event listener will fire after the downloaded file’s first frame actions have been executed. This will be helpful for performing any actions on the loaded file. Until this event listener fires, you cannot perform any actions on the loaded file.
Note: If there is any problem loading the file then MovieClipLoader.onLoadErrorevent listener will fire and return the error code.
Now let us see an example of how to use the MovieClipLoader class in action.
Example:
// Instantiate MovieClipLoader Class
var adloader:MovieClipLoader = new MovieClipLoader();
// use loadClip to load SWF file into a movie clip header_mc
adloader.loadClip("mainad.swf","header_mc");
// Add an onLoadStart event listener to show the progress of the loading
adloader.onLoadStart = function (targetMC){
var loadProgress:Object = adloader.getProgress(targetMC);
var loaded:Number = loadProgress.bytesLoaded;
var total:Number = loadProgress.bytesTotal;
adprogress_txt.text = loaded+" of "+ total+" bytes loaded";
}
// Add an onLoadComplete event listener to clear the loading information
adloader.onLoadComplete = function (targetMC){
adprogress_txt.text = "";
}
// Add an onLoadError event listener to trace the load errors
adloader.onLoadError = function (targetMC, errorCode){
adprogress_txt.text = "ERRORCODE:" + errorCode + " failed to load";
}
Next: XML Class >>
More Flash Articles
More By Adi Reddy Mora