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 Send Data to PHP and Return Tutorial

This Flash ActionScript PHP tutorial series shows how to send data from ActionScript to PHP and returned back to AS.

The procedures are similar to Flash ActionScript and PHP one way communication except the loading method. In Flash ActionScript and PHP two way communication, the URLLoader.load( ) method is used. The URLLoader.load( ) method should be used when we need the sent variables returned back to Flash ActionScript.

It involves involves the following steps:

  1. Create A new URLVariables instance to work with to store the variable.
  2. Create variables that need to send to PHP file.
  3. Create a new URLRequest instance sending data to the specified PHP file.
  4. The data property of the request is set to the URLVariables instance to send to the PHP file.
  5. Create a new instance of the URLLoader class to work with.
  6. Specify dataFormat property of the URLLoader to be "VARIABLES".
    (This ensure that variables loaded into Flash with same variable names)
  7. Load the PHP file by using URLRequest.
  8. Display the output of the PHP file when the loading is completed.

Flash ActionScript Codes:

// Create A new URLVariables instance to store the variable
var myVariables:URLVariables = new URLVariables();

// Create a variable (e.g. candidate) to send
myVariables.candidate = "Alex";

// Create a new URLRequest instance sending data to "ascom01.php"
var myRequest:URLRequest = new URLRequest("ascom01.php");

// Send data using the POST method
myRequest.method = URLRequestMethod.POST;

// The data property of the request is set to the
// URLVariables instance (myVariables) to send to the PHP file.
// Note: myVariables stored the variable (e.g. candidate)
myRequest.data = myVariables;

// Create a new instance of the URLLoader class to work with.
// URLLoader.load( ) method should be used when we need the
// sent variables returned back to Flash ActionScript.
var myLoader:URLLoader = new URLLoader;

//specify dataFormat property of the URLLoader to be "VARIABLES"
//This ensure that the variables loaded into Flash with the same variable names
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;

//Load the PHP file by using URLRequest
myLoader.load(myRequest);

 

//Display the value with variable name "phpConfirm"
output_txt.text = evt.target.data.phpConfirm;

 

 

Remarks:

This Flash Actionscript 3 PHP communication tutorial discuss how to send data from AS to PHP and return.