In this tutorial we’ll see how to pass complex data from php to flash, without using AmfPhp but also without the “classic” format readable by flash…this can bea n intermediate solution: AmfPhp is for large amount of data, and the classic “var=value&var2=value2&…” is for small/simple data-types…what can we do when we have a little amount of complex data, or a medium amount of simple/complex data ? Well…we can use the serializer class!
1b) What we need
a) Serializer Class (downloadable at http://sourceforge.n...rializerclass/) – An excellent class, a Sephiroth’s ( http://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
Var=value&var2=value2….
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”


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 won’t use database, .txt files and other, but only a .php files with “fixed” data….obviously you can take data wherever you want, but I thought that use a data-source (eg a database) in this tutorial hadn’t a practice utility, it’d only make the tutorial more complex and longer…I preferred made things simple


2) Let’s go!
Well, before start, I created the files (serializer.fla and serializer .php). I’ve also downloaded the .mxp file.
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 you find at the URL
http://www.brolyweb.com/Tutorials/Serializer/InstallaClasse.swf.
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

2b) The PHP file
For class testing, we need a php file that have to pass to flash some complex data (array, objects, etc). Let’s write, into “Serializer.php”, some simple code-lines with an array containing different object types…
Now, we can see if it really pass data urlencoded and serialized…then we can put the .php on our webspace (or into our local test directory) and visit it in a brower.
The browser’d show this
ToFlash=a%3A3%3A%7Bi%3A0%3Bb%3A1%3Bi%3A1%3Bs%3A11%3A%22Hello+world%22%3Bs%3A6%3A%22number%22%3Bi%3A1%3B%7D
(http://www.brolyweb.com/Tutorials/Serializer/Serializer.php)
2c) The flash side
After the PHP code, it’s time to open Flash
Create Serializer.fla (or open it), and in the first frame write this code
(change the path into lV.load to your. Php file)
See the video at URL.
http://www.brolyweb.com/Tutorials/Serializer/Serializer.swf
As you see, after inserted the code, if you test your flash movie, you’ll have a variable that have the same values that where in the PHP array…simple, true?

3) Bye…and a preview
In this tutorial we saw how to receive serialized data from php…but if we’d do the vice-versa, send serialized data from flash to php? Well, it’s that we’ll see in next tutorial, friends
I hope you like this tutorials with video inserts that show some passages

(please note: I haven't insert the .swf videos into the thread because they were too large, if I publish it at less than that size they became incomprensible

This post has been edited by Broly: 17 December 2004 - 05:15 PM