Return to Snippet

Revision: 6546
at May 29, 2008 12:28 by narkisr

Initial Code
    import flash.utils.ByteArray;
    import mx.utils.Base64Encoder;
    import mx.utils.Base64Decoder;
    public class SerializationUtils {
        public static function serializeToString(value:Object):String{
                throw new Error("null isn't a legal serialization candidate");
            var bytes:ByteArray = new ByteArray();
            bytes.position = 0;
            var be:Base64Encoder = new Base64Encoder();
            return be.drain();
        public static function readObjectFromStringBytes(value:String):Object{
            var dec:Base64Decoder=new Base64Decoder();
            var result:ByteArray=dec.drain();
            return result.readObject();

Initial URL

Initial Description
This snippet shows how to serialize action script object to strings, the serialization method is AMF based, note also that each object must meet three basic rules in order to be serialized properly: 
   ¨1. The constructor must take no arguments
   2. Fields must be public or they won’t be saved
   3. You must register it with a class alias by calling, class).¨
(this is based upon

Initial Title
Action script to string serialization and de-serialization

Initial Tags
actionscript, Flex

Initial Language
ActionScript 3