Pass PHP Multiple Variables to Flash ActionScript Tutorial
The previous Flash ActionScript 3 PHP communication tutorial only pass a single PHP variable to Flash AS. This tutorial shows how to pass multiple PHP variables to Flash ActionScript.
Flash Tutorial Content:
This is a basic Flash ActionScript PHP communication tutorial. It only pass a single PHP variable to Actionscript.
The Flash Movie of this tutorial is shown as above.
PHP File Codes:
<?php
$candidate = "Alex";
$t=time();
$tDate = date("D F d Y",$t);
echo "Candidate=" . $candidate . "&" . "Date=" . $tDate;
?>
The output of the PHP file is "Candidate=Alex&Date=current date" which is name-value pairs variables joined by the "&" character.
Flash ActionScript Codes:
// define the PHP file that will be loaded
var phpFile:String = "myfile1.php";
function loadFile(evt:MouseEvent):void {
//Create a URLLoader object with the name myLoader
var myLoader:URLLoader = new URLLoader();
// Specify dataFormat propery of the URLLoader to be "VARIABLES"
// This ensure variables loaded into Flash with same variable names
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
// Create a new URLRequest object specifying the location or URL
// of the PHP file.
var urlRequest:URLRequest = new URLRequest(phpFile);
//Load the PHP file into the loader by using URLRequest
myLoader.load(urlRequest);
//Listen when the loading of PHP file COMPLETE
//Call the loadComplete function when the loading COMPLETE
myLoader.addEventListener(Event.COMPLETE, loadComplete);
}
function loadComplete(evt:Event):void {
// Display the value with variable name "Candidate"
candidate_txt.text = evt.target.data.Candidate;
//Display the value with variable name "Date"
date_txt.text = evt.target.data.Date;
}
// Hook up the button with the function loadFile
enter_btn.addEventListener(MouseEvent.CLICK, loadFile);
Download Flash Source File:
Remarks:
This Flash ActionScript tutorial shows how to pass multiple PHP variable to AS.
