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 (1)

In a pratical Flash application, the records extract from the MySQL database are usually display in a table. In this Flash ActionScript PHP MySQL tutorial, we use Flash DataGrid component to display 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 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 same as 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);

$phpConfirm = "";

$counter = 0;

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

$domain = $row["domain"];
if ($counter == 0) {
$phpConfirm .= $domain;
} else {
// Use a item limiter "|" to seperate the records
$phpConfirm .= "|" . $domain;


echo "phpConfirm=" . $phpConfirm . "&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


//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("apm01.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 "phpConfirm"
var myResult:String = evt.target.data.phpConfirm;

//Split the string into an Array
var myArray:Array = myResult.split("|");
//output_txt.text = "The number of items are: " + myArray.length;

//var finalString = "";

// Clear the DataGrid

var i:int;

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

//Add the Items to DataGrid
myDataGrid_dg.addItem( {Name: myArray[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-03.fla


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