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 Load External Plain Text File Tutorial

The loading of external plain text files with Flash ActionScript 3 are basically involves the following steps:

  1. Create a new instance of the URLLoader class to work with.
  2. Specify dataFormat property of the URLLoader to be "TEXT".
    (This step is optional because the DataFormat is TEXT by default. )
  3. Create a new URLRequest object specifying the location or URL of the external plain text file.
  4. Load the text file by using URLRequest
  5. Display the content of the text file.

The Flash ActionScript loading external plain text file can be illustrated with the following diagram:

flash actionscript 3 load external plain text file

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);

 

//Display load completed in Message Box
output_txt.text = evt.target.data as String;

 

Remarks:

The default dataFormat of URLLoader is "TEXT".