Send Variables from Flash ActionScript to PHP Tutorial
Flash ActionScript can send data to PHP files easily. The basic concept is create a new URLRequest instance to contain the variables and pass it to PHP file for processing with either sendToURL( ) method or navigateToURL( ) method. Since we wish to demonstrate the result by opening a new browser window, the tutorials will use the navigateToURL() method. It involves involves the following steps:
- Create A new URLVariables instance to work with to store the variable.
- Create variables that need to send to PHP file.
- Create a new URLRequest instance sending data to the specified PHP file.
- The data property of the request is set to the URLVariables instance to send to the PHP file.
- Use the navigateToURL( ) method to send data to PHP file for processing.
The process of sending data from Flash ActionScript to PHP file can be illustrated with the following diagram:
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 "myfile21.php"
var myRequest:URLRequest = new URLRequest("myfile21.php");
// The data property of the request is set to the
// URLVariables instance (myVariables) to send to the PHP file.
myRequest.data = myVariables;
// Use the navigateToURL( ) method to send data to PHP file for processing
This Flash ActionScript PHP tutorial discuss how to send data from Flash AS to PHP.