Tag Archives: AS2

Flash(AS2) + PHP + MySql

Last couple of month was working on Flash. Became familiar with Flash and started loving it… 🙂 Then a project came they
asked for making CMS for their flash site. You can see the site http://www.zfp.com

And the game started… 🙂

Started learning AS2 and loadvars. Faced lots of difficulties and finally manged to communicate with Flash(AS2) + PHP + Mysql.
In this post I will try to give basic idea to communicate Flash(AS2) and PHP.

1. Flash(AS2)

lv_th = new LoadVars();

lv_th.onData = function(varText:String)

{

 temp = varText.split('@@');

 photo= temp[0].split('|');

 photo_title = temp[1].split('|');

 photo_description = temp[2].split('|');

};

lv_th.load("photo_gallery.php?gallery_id=5");


1. PHP+MySql


$gal_id = $_GET['gallery_id'];
$sql = "SELECT * FROM gallery WHERE gal_id=$gal_id ORDER BY gal_id";
$result = mysql_query($sql) or die(mysql_error());
$photo = array();
$photo_title = array();
$photo_description = array();

while($rows = mysql_fetch_object($result))
{
    $photo[]             = $rows->photo;
    $photo_title[]       = $rows->title;
    $photo_description[] = $rows->description;
}

print implode('|',$photo) . '@@' . implode('|',$photo_title) . '@@' .
implode('|',$photo_description);


First one is flash AS2 Code to get the data from php. It first create a new instance LoadVars();

then onload called the photo_gallery.php?gallery_id=5 and wait for the response to come.

In php we made the query based on the gallery_id and get the data and put it in three separate

array. then we implode each array values with ‘|’ and separate each array with ‘@@’.

In flash after getting the data as a string in varText variable we split it by ‘@@’ to separate the

different array values and after that separte it in ‘|’ to get each value. Now we have all the data

in photo, photo_title and photo_description array. Use the array values as you want…. 🙂

Note: In the data there should not be ‘@@’ or ‘|’. If it contains then you have to choose the separator carefully. Choose a separator which is not come as data.

Have fun with flash + php + MySql….. 😉