This content has been marked as final. Show 2 replies
There area a couple of different things that can make this confusing:
First, there is a difference between creating a copy, and creating a reference. Specifically, Numbers, Strings, and Booleans are primitive values, so when you do this: myVar1 = myVar2, it basically copies the value of myVar2 into a new variable, named myVar1. However, complex data types, such as Arrays and generic Objects, do not copy the value, but rather create a reference. So when you do myArr1 = myArr2, you are just creating another reference named myArr1 to the same Array, which is referenced to by myArr2.
Solution is to copy the array. There is not Array.clone() method, but you can effectively do it like this:
myClonedArr = myArr.slice();
Second, a SharedObject is automatically flushed when the client is closed. The only thing that SharedObject.flush() does for you is prompt the user for more disk space if the Player needs more than the default 100K.
Thanks for the explanation. It doesn't make my life any easier, but it is good to know why the shared object does what it does!
I did find a workaround for the array problem by first using .join("-") to group everything together into one string when saving, and then using .split("-") to break it back apart when retrieving. Saving objects, however, will be a little trickier.