开发者

Serializing an array in Flash AS3

I need to serialize and unserialize (is that even a word?) an array in AS3, so it can be sent as a string.

The only problem is that it doesnt just contain text, it contains objects.

Is it possible to serialize and unserialize arrays in AS3 like you can in PHP? How can I do so?

Once this bug is fixed,开发者_运维问答 all will be well with my program.

EDIT: I need to be able to sync an array across several flash files, which are connecting via TCP and can send simple things like strings and integers, so I need to be able to transmit data about this in one go, in string form.


If your goal is to communicate between clients over TCP, then simply serialize the objects with AMF using writeObject method on your socket. I'm not sure if this is at odds with your "in string form" requirement, as it is more of a binary format for efficiency.

Edit: Write the object to a ByteArray and then Base64 encode it to produce a string. This would be similar to how some web services deal with binary data, since it has to be places into a string format that places nicely with xml, and base64 contains all printable characters.

You can even compress the bytearray before you encode it, to make is smaller for sending across the wire.

ByteArray: http://livedocs.adobe.com/flex/3/html/help.html?content=ByteArrays_2.html

There is a Base64 library attached in this forum thread, you can find other libraries on the internet: http://www.flexdeveloper.eu/forums/actionscript-3-0/compress-and-uncompress-strings-using-bytearray


maybe you should look at this page, its kind of similar with what you are trying to do

http://www.actionscriptdeveloper.co.uk/serializing-and-unserializing-svg-objects-to-arrays-in-actionscript-3/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜