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

Send an Input Data from Flash ActionScript to PHP and Returned Back

This Flash ActionScript 3 and PHP tutorial shows how to send an input data from ActionScript to PHP and return back to PHP.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

In most Flash application, the data send to PHP are usually input by the user. In this Flash ActionScript PHP tutorial, an input data is sent to the PHP file.

The Flash Movie of this tutorial is shown as above.

PHP File Codes:


// $candidate is the variable send from Flash Actionscript
$candidate= $_POST['candidate'];

// Confirm to Flash ActionScript that the data has been received
echo "phpConfirm=Greeting " . $candidate . "! I got your data. Thanks" ;


The output of the PHP file is "phpConfirm=Greeting Alex! I got your data. Thanks".

Flash ActionScript Codes:

function checkComplete(evt:MouseEvent):void {

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

// Create a variable (e.g. candidate) to send
myVariables.candidate = candidate_txt.text;

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

//Listen when the loading of data COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);



// Hook up the button with the function checkComplete
enter_btn.addEventListener(MouseEvent.CLICK, checkComplete);

// This is the function that display the data returned back from PHP file
function loadComplete(evt:Event):void {

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



Download Flash Source File:

Flash Source File as3-php-two-communication-02.fla


This Flash ActionScript tutorial shows how to send input data from Actionscript to PHP and return back.