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 Text File with Variable Tutorial

The loading of external text files with variables with Flash ActionScript 3 are basically the same as loading plain text files. It also 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 "VARIABLES".
    (Need to parse the data of the external text file contained name-value pairs variable, for example, Candidate=Alex&Post=Production Engineer)
  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 text files with variables can be illustrated with the following diagram:

flash actionscript 3 load external text file with variables

Flash ActionScript Codes:

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

 

// Specify dataFormat propery of the URLLoader to be "VARIABLES"
// Allow parse data of the external text file contained name-value pairs variable

myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

 

// Create a new URLRequest object
// specifying the location or URL of the external text file.

//Content of the text file:
/*
Candidate=Alex
&Post=Production Engineer
&Comment=Recommend Hire
*/
var myRequest:URLRequest=new URLRequest("application.txt");

 

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

myLoader.load(myRequest);

 

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

 

Remarks:

This flash ActionScript tutorial discuss the loading of external text file with variables.