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: Load External Text File and Image

This Flash ActionScript tutorial show how to load an external text file with variables. However the variable in the text file also include link to an external image.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In previous Flash ActionScript tutorials, we only load the text contents of the external text file into the text fields of Flash Movie. Actually we can also put a "text link" to the variable of the text file. Therefore the external image will be loaded when the external text file is loaded to the Flash Movie.

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.

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
//Content of external text file:
&Post=Production Engineer
&Comment=Recommend Hire
myLoader.load(new URLRequest("application.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;


//Load the image
var loader:Loader = new Loader()
loader.load(new URLRequest(evt.target.data.Pic))


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



///// ERROR HANDLING /////

myLoader.addEventListener(IOErrorEvent.IO_ERROR, loadError1)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadError1)
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, loadError2)


function loadError1(event:ErrorEvent):void {

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



function loadError2(event:HTTPStatusEvent):void {

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



Download Flash Source File:

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

Text File: application.txt


We rarely load texts only in Flash application. The loading usually include both texts and images. The next Flash ActionScript tutorial will show how to link to an external image in the variable of the text file.