Flash ActionScript 3 Tutorial: Load External swf Flash Movie with COMPLETE Event
The first flash ActionScript tutorial simply loaded the external swf movies into the main Flash Movie assume that everything goes well. However a better approach is to monitor the whole loading process of the external swf movies. This include when the loading is completed? What if an error happens during the loading process? How to inform the users when errors happen during the loading process. This Flash ActionScript tutorial shows how to listen when the loading is completed?
Flash Tutorial Content:
The codes in previous Flash ActionScript tutorial was blindly load the external swf files and display them on the MainTimeline assume that everything went well. A little better approach is to display the external swf file only when the loading process is completed.
The complete Flash Movie is shown as above, you may try to play around how it works before you start this Flash ActionScript tutorial.
Flash ActionScript Codes:
// Create a new Loader to load the swf files
var myLoader:Loader=new Loader();
function checkComplete(evt:MouseEvent) {
var myRequest:URLRequest=new URLRequest("glow.swf");
// Load the external movie into the Loader
myLoader.load(myRequest);
}
movie1_btn.addEventListener(MouseEvent.CLICK, checkComplete);
// Listen when the loading of movie (glow.swf) is completed
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadMovie1);
function loadMovie1(myEvent:Event):void {
addChild(myLoader);
// Set display location of
myLoader.x = 200;
myLoader.y = 80;
}
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial shows how to listen when the loading process is completed. The above codes will display the external swf file when the loading process is completed. However sometimes errors may happen, for example, you change the file names of the external movies but forget to update the codes. Therefore this is always better to include error checking in your codes. The next Flash ActionScript tutorial will show how to do that.