Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Flash ActionScript 3 Tutorial: Handle Error During Loading External Flash swf File (2)

The most common errors arise during the loading process are IO Error and Secutiry Error. A good practise is checking the errors one by one during the loading of external swf files.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

The codes in previous Flash ActionScript tutorial will check both IOErrorEvent and SecutiryErrorEvent when an error happens. However you can check the error during the loading of the external swf files in two steps. The first step will check with IOErrorEvent. If there is no any error with IOErrorEvent, then try to load the external swf file into the Loader. If an error happens at this stage, the SecurityErrorEvent error message will be displayed. Otherwise the external swf movie will finally be displayed on the MainTimeline.

The complete Flash Movie is shown as above, you may try how it works before you start this tutorial. Same as previous tutorial, the file name of the external swf file is wrong due to typing mistake. Therefore the external swf Flash Movie cannot be displayed on the MainTimeline. And the error message will be shown on the message box.

Flash ActionScript Codes:

// URL of the external movie content
var myRequest:URLRequest=new URLRequest("glow2.swf");

 

// Create a new Loader to load the swf files
var myLoader:Loader=new Loader();

 

// 1st level IO_ERROR input and output error checking
// Listen error events for the loading process
myLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioError);

function ioError(event:ErrorEvent):void {

// Display error message to user in case of loading error.
output_txt.text = "Sorry that there is an IO error during the loading of an external movie. The error is:" + "\n" + event;

}

 

function checkComplete(evt:MouseEvent) {

// 2nd level SecurityError error checking
// Use the try-catch block
try {
// Load the external movie into the Loader
myLoader.load(myRequest);
} catch (error:SecurityError) {// catch the error here if any
// Display error message to user in case of loading error.
output_txt.text = "Sorry that there is a Security error during the loading of an external movie. The error is:" + "\n" + error;
}

}

 

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 {

// Display the Loader on the MainTimeline when the loading is completed
addChild(myLoader);
// Set display location of the Loader
myLoader.x = 200;
myLoader.y = 80;

}

Download Flash Source File:

Flash Source File load-swf-5.fla

Remarks:

An ActionScript tutorial of loading external Flash swf file without the topic of preloader seems to be incomplete. In the next Flash ActionScript tutorial, we will show show to make a very simple text preloader.