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 Tutorial: Error During Load External Text File

In previous Flash ActionScript tutorials, we assume that the loading process of the external text files was smooth and completed without any problem. This come another question. What if an error happens during the loading process?

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

Sometimes errors may happen during the loading process, for example, you change the file names of the external text file but forget to update the ActionScript codes. Therefore this is always better to include error checking in your ActionScript codes.

The complete Flash Movie is shown as above, you may try how it works before you start this Flash ActionScript tutorial. Select the Flash Movie and click on the Play button. The file name of the external text file is wrong due to typing mistake. Therefore the external text File cannot be loaded properly. An annoying error message box may be pop up. However the user do not know what happens. You properly came across this kind of error before.

Flash ActionScript Codes:

//Create a URLLoader object with the name myLoader
var myLoader:URLLoader = new URLLoader();

 

//specify dataFormat property of the URLLoader to be “VARIABLES”
//This ensure that the variables loaded into Flash with the same variable names
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

 

function checkComplete(evt:MouseEvent) {

//Load the text file by using URLRequest
//Can be local file or URL of webpage
//WRONG file name of the external text file
myLoader.load(new URLRequest("application1.txt"));

}

 

enter_btn.addEventListener(MouseEvent.CLICK, checkComplete);

 

//Listen when the loading of text file COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);

 

function loadComplete(evt:Event) {

//Display load completed in Message Box
output_txt.text = "The text file was loaded successfully!";

 

//Display the value with variable name "Candidate"
//HTML tag is accepted
candidate_txt.htmlText = "<b>" + evt.target.data.Candidate + "</b>";

 

//Display the value with variable name "Post"
post_txt.text = evt.target.data.Post;

 

//Display the value with variable name "Comment"
comment_txt.text = evt.target.data.Comment;

 

//Remove Listener that no longer in use
myLoader.removeEventListener(Event.COMPLETE, loadComplete);

}

Download Flash Source File:

Flash Source File load-text-file-4.fla

Remarks:

The above ActionScript codes will not display the content of the external text file when there is an error during the loading process. An annoying error message box may be pop up. The users do not know what happen. Therefore this is better to inform the users that an error happens for the Flash Movie. And the users can inform the website Administrator about the error. The next Flash ActionScript tutorial will show how to do that.