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 PHP MySQL Tutorial - Display Records in Datagrid Component (2)

In previous Flash ActionScript PHP MySQL tutorial, we use Flash DataGrid component to display one column of the records. In this tutorial, we display two columns of the records.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This Flash ActionScript PHP and MySQL communication tutorial shows how to use Flash DataGrid Component to display multiple columns of the records.

The Flash Movie of this tutorial is shown as above.

MySQL DataBase Table Records

We are using the the same database records in this tutorial:

MySQL database

PHP File Codes:

The PHP codes are only a bit difference from previous example:


$username = $_POST['username'];

// create connection
$connection = mysql_connect("localhost", "db_user", "db_password") or die ("Couldn't connect to the server.");

// select database
$db = mysql_select_db("db_name", $connection) or die ("Couldn't select database.");

// create SQL
$sql = "SELECT domain FROM db_table where username = '$username'";

// execute SQL query and get result
$sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query.");

// get number of rows in $result.
$num = mysql_numrows($sql_result);

$domain_list = "";
$hosting_list = "";

$counter = 0;

while ($row = mysql_fetch_array($sql_result)) {

$domain = $row["domain"];
$hosting = $row["hosting"];

if ($counter == 0) {
$domain_list .= $domain;
$hosting_list .= $hosting;
} else {
$domain_list .= "|" . $domain;
$hosting_list .= "|" . $hosting;


echo "domainList=" . $domain_list . "&hostingList=" . $hosting_list . "&totalItem=" . $num;

// free resources and close connection


There are two variables return back to Flash ActionScript:

- phpConfirm

- totalItem

Flash ActionScript Codes:

//Add Items to ComboBox
memberCombo.prompt = "Please select a user";
memberCombo.addItem( {label: "alex" } );
memberCombo.addItem( {label: "kathy" } );
memberCombo.addItem( {label: "peter" } );


//Add the Combo Header

myDataGrid_dg.addColumn("Hosting Plan");


//Add CHANGE event listener to ComboBox
//Whenever the index of Combox CHANGE, function checkComplete will be called
memberCombo.addEventListener(Event.CHANGE, checkComplete);

function checkComplete(evt:Event):void {

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

// Create a variable (e.g. candidate) to send
myVariables.username = evt.target.value;

// Create a new URLRequest instance sending data to "ascom01.php"
var myRequest:URLRequest = new URLRequest("apm04.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);


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

//Display the value with variable name "totalItem"
total_txt.text = evt.target.data.totalItem

//Get the value (string) with variable name "domainList" and hostingList
var myResult1:String = evt.target.data.domainList;
var myResult2:String = evt.target.data.hostingList;

//Split the string into an Array
var myArray1:Array = myResult1.split("|");

var myArray2:Array = myResult2.split("|");

// Clear the DataGrid

var i:int;

for (i = 0; i < myArray1.length; i++) {

//Add the Items to DataGrid
myDataGrid_dg.addItem( {"Name": myArray1[i], "Hosting Plan": myArray2[i]} );


//Set the width of the DataGrid (Not width of single column)
myDataGrid_dg.width = 250;


//The Height of row can be set in Parameter window, or
myDataGrid_dg.rowHeight = 25;


//Set number of row
//Set equal to the number of row to auto fit the row
myDataGrid_dg.rowCount = i;



Download Flash Source File:

Flash Source File as3-php-mysql-04.fla


This Flash ActionScript tutorial also shows how to use Actionscript interact with PHP and MySQL, then display the MySQL records in Flash DataGrid Component with multiple columns.