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

Pass PHP Plain Text Output to Flash ActionScript Tutorial

Flash ActionScript can connect or interact with PHP files easily. The output of the PHP files in this tutorial series are simply plain text, i.e. without variable. The procedures are same as the Flash ActionScript loading external plain text files. It also involves 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 PHP file.
  4. Load the PHP file by using URLRequest
  5. Display the output of the PHP file.

The Flash ActionScript and PHP interaction can be illustrated with the following diagram:

flash actionscript 3 php communication

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".