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

This tutorial also show how to load an external text file into a text field with Flash ActionScript.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This Flash ActionScript tutorial is similar to the first tutorial. This time we declare the URL of the external text file first. Actually this is more flexible to use this method to write ActionScript 3.

The Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

//You can declare the url of the text file as string
//so that you can use it later
var url:String = "story.txt";

 

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

 

//Load the text file by using URLRequest
//Can be local file or URL of webpage
myLoader.load(new URLRequest(url));

 

//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-2.fla

Remarks:

In the first two Flash ActionScript tutorials, the external text file is simply a text string. In the following ActionScript tutorials, the text file is actually a small database. There are variables, and a value will be assigned to each variable.