Currently, I do serialize my model object to the SharedObject instance:
try {
var mySo:SharedObject = SharedObject.getLocal("sig");
mySo.clear();
mySo.data.model = _model;
mySo.flush();
} catch ( e:Error ) {
Alert.show( 'Leider konnte kein Modell geladen werden.' );
}
Likewise, I load the saved model using the SharedObject instance. Works great.
Ultimately, I'd like to serialize it to a file - which fails. Here is how:
var fp: File = File.applicationStorageDirectory;
fp = fp.resolvePath( PREFS_FILENAME );
var _prefsStream:FileStream;
_prefsStream = new FileStream();
_prefsStream.open( fp, FileMode.WRITE );
_prefsStream.endian = Endian.BIG_ENDIAN;
_model.writeExternal( _prefsStream );
_prefsStream.close();
The complementing read operation suddenly breaks and reports missing bytes.
In fact, I can't image how FileStream / _model.writeExternal() is able to serialize, since it needs to somehow know, that a new serialization operation is about to start. If it doesn't know, it won't be able to determine, which object instances are left to serialize.
Thus, I image that my concept is completely wrong or I missed how to initialize the serialization operation.
Please explains, what I'm missing.
I'd be happy to read the raw ByteArray from the shared object and write it to a file. Unfortunately, I didn't find a method to retrieve from a SharedObject a ByteArray of a certain property, in my case mySo.data.model
.
My question is loosely related to this one: Why does delete( DictionaryInstance[ key ] ); fail?