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 (1)

This tutorial series show how to load external text files with ActionScript 3 with Flash CS3. The first two tutorials will show how to load an external text file into a text field. The external text file is a simple story...

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

Many Flash Movies require to load external text files. The text file may be a small database or simply some information. In this Flash ActionScript tutorial, we load an external text file which is simply a story into a text field of the Flash Movie.

The first Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

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

 

// Specify dataFormat propery of the URLLoader to be "TEXT"
// (This step is optional since the default dataFormat is "TEXT"

myLoader.dataFormat = URLLoaderDataFormat.TEXT;

 

// Create a new URLRequest object
// specifying the location or URL of the external text file.
var myRequest:URLRequest=new URLRequest("story.txt");

 

// Call the load( ) method to load the external file
// with the URLRequest object as the parameter.

myLoader.load(myRequest);

 

// Note: The above two lines of codes can be combined into one line:
// myLoader.load(new URLRequest("story.txt"));

 

//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 = evt.target.data as String;

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

}

Download Flash Source File:

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

Remarks:

This Flash ActionScript tutorial shows how to load the text file with the file name by using URLRequest. In most cases, we would like to declare the URL of the text file first. And then load the text file with the URL variable by using URLRequest. The next Flash ActionScript tutorial will show you how.