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..
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();
//Load the text file by using URLRequest
//Can be local file or URL of webpage
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) {
output_txt.text = evt.target.data as String;
//Remove Listener that no longer in use
myLoader.removeEventListener(Event.COMPLETE, loadComplete);
}
Download Flash Source File:
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.