Currently Browsing: AIR

Flex / AIR Serialization Lessons Learned

A few lessons learned while serializing custom classes.

Compiler metadata tags only get you part of the way. Metadata alone is perfectly suitable when you’re not serializing classes with members that contain complex datatypes where those complex types have private members.
serialization metatdata tags

If there are private members in your complex data types then you’ll need to implement IExternalizable.
implement IExternalizable

IExternalizable requires implementing two methods, ‘readExternal’ and ‘writeExternal’.
iexternalizable implementation example

Another thing to watch out for is that it appears you must use a no args constructor in order to deserialize an object. If anyone knows otherwise please leave details in the comments.
serialization no args constructor

AS3 makes it ultra simple to serialize variables via the IDataInput and IDataOutput objects. You just need to remember, when writing out things like Strings, to use writeUTF / readUTF rather than writeUTFBytes / readUTFBytes. The writeUTF method inserts a UTF string representing the number of bytes in each String which means you don’t have to do any grunt work when deserializing with readUTF — nice.

Page 7 of 7« First...34567