This tutorial is the 2nd part about the use of Sephiroth’s ( http://www.sephiroth.it ) Serializer Class.
If in the 1st part we saw how receive data in flash from php, now we make the vice-versa, send serialized data from flash to php.
General guidelines are the same of the 1st part, but I’ll rewrite them for those who haven’t read the first part and maybe are interested only in the data sending from flash to php
1b) What we need
a) Serializer Class (downloadable at http://sourceforge.n...rializerclass/) – An excellent class, a Sephiroth’s (www.sephiroth.it) idea that became an useful realty
As said before, this class allows to pass complex dates from php to flash without the “classic” format
that with a medium amont of data can be very very boring and hard to use, but it allows to pass directly more complex objects (eg Arrays)
This is the official class description
“Serializer Class enable (For Macromedia Flash) you to pass and receive complex data type from and to PHP and Flash using the native PHP functions serialize and unserialize. Flash received data will be a native Flash object”
b ) Flash mx 2004 (I think you know it , if you haven’t it you can find a trial on www.macromedia.com)
c) A local webserver, or an hosting, where test our little example (it must have PHP support)
d) Macromedia Extension Manager (free, downloadable from www.macromedia.com), wich we’ll use for install the Serializer Class Extension
1c) Last notes before start
In this tutorial, we see simply how the data-passage works, we’ll simply have an AS code with fixed data, without user input or other…the purpose of this tutorial is only to show how an array with different object-types can be easly passed to php.
2) Let’s go!
Well, before start, I created the files (serializer.fla and serializer .php). I’ve also downloaded the .mxp file. You see here my start situation.
NOTE: Obviously you can also create .fla and .php during the tutorial, and not immediately…I preferred create now the files for show how they’ll be
2a) Serializer Class installation
Now, first thing to do is install the Serializer class.
Double click on .mxp file … follow the video instructions below.
As you see, after the installation, you’ll have a “Serializer” name into the Extension Manager (ehm..I’ve a lot of extension installed now, but if you have less caos then me you found it immediately ). Selecting the Serializer into the Extension Manager you can see a little sample-ActionScript code (in particular, the first lines,
You can see with your eyes, it’s very easy. Now I’ll explain you pass-by-pass how to try if the class works correctly, with a small example.
2b) The Flash file
Different from the 1st part of this tutorial, this time we start from the flash file (it’s logic…we must send data from flash to php…it would be absurd start from the php file without know what flash sends to him )
As you can see in the video below, we simply write an array with different types (number,Boolean,string,…) of data, then send it to php using LoadVars.send.
The code to insert in first frame is
NOTE: I used the SEND method because it open a new window, that in this example is useful for better see the .php page results, but it send data only in GET, then imho when possible it’s better to use sendAndLoad, the .php page will exec the same operations without to be shown, and you can use POST method.
With this code, we’ve an array with this data
 => 1
 => 2
 => “hello world”
 => Array ( => “a”  => “b”  => “c”)
2c) The PHP code
Well’, here we’are at the last part of the tutorial.
First of all, read what Sephiroth say about the serialize method
Serialize the data to being passed to a PHP page. The serialize method will automatically escape() the string to be passed. Check your php setting for get_magic_quotes_gpc(). Probably you need to stripslashes the arrived data.
serialized = Serializer().serialize(myArray)
It means that, in php file, it can be necessary use stripslashes on the received data.
Let’s see the code of the .php file.
What it means?
It’s simple. If get_magic_quotes is active in the php.ini , it’s necessary to use stripslashes…and in fact we do it, on the $_GET[‘serialized’] var, that’s the var containing flash-sent data (in fact, as you remember, in flash we used lV.serialized = …. )
Once used (or not) stripslashes, we unserialize and urldecode the var ….
Print_r ($l) it’s only for this example, to show that the data in php will the same data sent by flash
In fact, if you test your movie, you should see something like the video below.
Read the php data…
Read the flash data…
Wow, they’re the same
With this 2nd part, I finish the tutorials about the interaction between Flash & Php using the Serializer Class. I hope you liked this two tutorial and that the explanation and the video are comprensible.
Se you at next tutorial, friends
This post has been edited by Broly: 06 August 2005 - 09:59 AM