Reputation: 167
I'm using:
import flash.utils.ByteArray;
import mx.utils.Base64Encoder;
import mx.utils.Base64Decoder;
.
.
.
public static function serializeToString(value:Object):String{
if(value==null){
throw new Error("null isn't a legal serialization candidate");
}
var bytes:ByteArray = new ByteArray();
bytes.writeObject(value);
bytes.position = 0;
var be:Base64Encoder = new Base64Encoder();
be.encode(bytes.readUTFBytes(bytes.length));
return be.drain();
}
public static function deSerializeFromString(value:String):Object{
var dec:Base64Decoder=new Base64Decoder();
dec.decode(value);
var result:ByteArray=dec.drain();
result.position=0;
return result.readObject();
}
But I keep getting an "Error #2030: End of file was encountered."
This is (probably) because the class I'm serializing is too big for the "String" object type in AS3.
Is there a limitless object for storing an array of characters (or better yet binary), or am I going to have to make my own class? (like one with an array of strings)
Upvotes: 2
Views: 1340
Reputation: 438
Another efficient, cross-platform way of serializing objects is by using JSON. Here is a library for as3: https://github.com/mherkender/actionjson
Upvotes: 2