Quantcast
Channel: PHP Website Development » PH
Viewing all articles
Browse latest Browse all 11

Save An Array From SWF and Store Using Actionscript 3 and PH

$
0
0

I have an AS3 project that takes user inputs (basically like a multiple choice test) and saves the these inputs in an array. I need to save the array to a text file so it can be reloaded when the app is reloaded. When the user returns to the application they can pick up where they let off.
I really just need to know what options I have for saving an array inside an swf to an xml file or text file in the same directory. Is this even possible.
Any ideas or concepts would be greatly appreciated.
thanks,
Laurence
………………………….

First, you need to serialize your object to a string. Then, post that string to a PHP script via a URLLoader instance. Store it as desired (database, text file, etc). When you need to reconstruct the object, load the string from your PHP script. Unserialize it and it’s ready to go.
For serialization and deserialization, here are helper functions:
private function serializeObject(o:Object):String
{
var ba:ByteArray = new ByteArray();
ba.writeObject(o);
return ba.toString();
}

private function unserializeObject(s:String):Object
{
var ba:ByteArray = new ByteArray();
ba.writeUTFBytes(s);
ba.position = 0;
return ba.readObject();
}
………………………….

You could store your variables as “Flash cookies” using the SharedObject class. It’s similar to the way PHP or Javascript store cookies locally on the user’s compupter. I wrote this Session class a while back: http://code.google.com/p/daleyjem/source/browse/trunk/com/daleyjem/as3/Session.as
It basically allows you to get, set and check if a set cookie exists.


Viewing all articles
Browse latest Browse all 11

Trending Articles