It's how shared objects work, for "ease of use".
A shared object is a container that has a *data segment that gets written to disk.
If you just grab the data segment after loading the shared object, you're referencing the object structure directly.
If you modify the data in the referenced object, you're also modifying data inside the shared object**.
Certain things (including closing the swf/tab/etc) will flush the current state of the shared object to disk***.
* This is done using structural encoding called AMF. If you have a custom class and serialize it, the *class path* itself gets serialized into the object. When you then load the object, Flash looks for that class to create an instance of it. If that class has gone missing****, or
no longer has properties that are in the serialized object, the whole thing breaks.
And now you know why TiTS saves things in the way it does. Everything is converted into a dynamic object with only basic data types (int, number, string, array, object), and the shared object is only open long enough to
immediately clone its data contents into another structure to avoid potential fuckery.
** Which is easy to do, because AMF makes it *feel* like the purposeful structure you've created with your custom classes is right there, and it's all nicely typed and has properties etc etc.
*** If you don't either a) explicitly "clone" (read: create a deep copy) the data segment, or (I think) b) reference the data segment elsewhere and then explicitly close the shared object, then you're effectively working directly on the object that will be saved again as soon as the swf closes.
**** Unless you add classpath overrides to tell the AMF system to use a different class in place of another. This still doesn't help you with missing properties though.
Consider some naive structure like (which is almost exactly what the character viewer was doing in parts):
Code:
var viewer_dongs:Array = new Array();
function new_character()
{
// this is a very common way to "clear" an array if you google such for as3.
viewer_dongs.splice(0, viewer_dongs.length);
}
function load_slot()
{
var savefile:SharedObject = SharedObject.getLocal("Save_1", "/");
viewer_dongs = savefile.data.dongs;
}
function removeADong(idx:int)
{
viewer_dongs.splice(idx, 1);
}
function addADong()
{
viewer_dongs.push(new Dong());
}
Load a save then anything you do will also modify the data in the shared object, as the arrays storing viewer data are actually parts of the shared objects internal data.
Spy dis