Edit:
(I see this same type of question was posted almost three years ago with no resolution, does anyone have a solution now?
http://www.kirupa.com/forum/showthread.php?t=275764)
I am trying to save a clone of a custom object (contains arrays and other custom objects as properties) to a Shared Object.
Basically I have a menu system that created this program, it’s running and at any point I want the user to be able to save it so he can go back to that exact point at a later date. Here is what I do so far:
- Pause the program
- The menu saves the variable that references the running program using a bytearray to a shared object
- A a later time, to load the program I pull the data from the shared object and save it to a variable, which I then treat like the original program
Here is my code to save the data:
var byteArrayCloner:ByteArray = new ByteArray();
byteArrayCloner.writeObject(myProgram);
byteArrayCloner.position = 0;
mySharedObject.data["myProgram_Running"] = byteArrayCloner.readObject();
mySharedObject.flush();
But it doesn’t work correctly, when I save the data I get several #1034 errors:
TypeError: Error #1034: Type Coercion failed: cannot convert Object@12ee0421 to org.papervision3d.core.proto.MaterialObject3D.
TypeError: Error #1034: Type Coercion failed: cannot convert Object@12f1d881 to flash.geom.Transform.
So I read how I am suppose to use “registerClassAlias” to remove those errors. I started adding them, like this:
registerClassAlias("SpriteAlias", Sprite);
The errors started to go away, I then tried:
registerClassAlias("TransformAlias", Transform);
This caused an error when I tried to save the data:
ArgumentError: Error #1063: Argument count mismatch on flash.geom::Transform(). Expected 1, got 0.
at flash.utils::ByteArray/readObject()
I don’t use flash.geom.transform, but I do use TweenLite, which uses it. What am I doing wrong here? How do you save a custom object to a shared object without any errors?
Thanks for any help.