Semi-Undocumented Adobe AIR File Serialization Issue

I’ve been having a major issue with Flex/Adobe AIR over the last week or so when serializing my data to files. I use a FileStream and call writeObject() on an ArrayCollection of my data. Pretty simple. Serializing seems to run fine, deserialization as well. The problem arises when I try to cast items in the collection to their appropriate type. It seems the objects have lost their type information and are plain Objects.

After a while of thumbing through the documentation it finally hits me. FileStream uses AMF3. Usually when using AMF3 you define RemoteClass metadata for each of your classes that mirror server-side classes. I had just assumed that since AIR knew I would be loading the object back in AIR again, it would do that stuff automatically. Turns out it doesn’t. A few lines of RemoteClass metadata later it’s working fine. You just need to define the alias as being your class with the full namespace typed out. Not in the documentation (or if it is, it needs to be in a more obvious spot such as here or here). Although knowing its was AMF3 format, I probably should have realized this sooner.

Hope this saves someone else some time.

3 Responses to “Semi-Undocumented Adobe AIR File Serialization Issue”

  1. mike chambers Says:

    Serializing objects is one of my favorite features of the file API.

    I posted a related example here:

    http://www.mikechambers.com/blog/2007/06/22/serializing-file-reference-instances-in-adobe-air/

    mike chambers

    mesh@adobe.com

  2. darron Says:

    I wrote about this last summer here: http://www.darronschall.com/weblog/archives/000271.cfm

    While not AIR-specific, the underlying issue is the same (AMF).

  3. Nathan Levesque Says:

    @darron, yes your post was what helped me realize I probably needed to use RemoteClass

Leave a Reply