Flash: SharedObject strange behavior

December 14th, 2005 by Luis

It seems that if you add or change an element of an array which has been stored in a SharedObject, this changes are saved automatically if you don't destroy the shared object before this changes are done.

Assuming that the shared object is locally persistent it makes some sort of sense, but only happens with arrays.

Must be a simple and logical explanation for this (I couln't find any documentation about it and I have my doubts considering this as a bug):

  1. var items_array:Array = new Array(1, 2, 3);
  2. var currentUserIsAdmin:Boolean = true;
  3. var currentUserName:String = "Ramona";
  5. var my_so:SharedObject = SharedObject.getLocal("superfoo");
  6. my_so.data.itemNumbers = items_array;
  7. my_so.data.adminPrivileges = currentUserIsAdmin;
  8. my_so.data.userName = currentUserName;
  9. my_so.flush();
  11. items_array.push(9);
  12. items_array[0] = 100;
  13. currentUserName = "Ramones";
  14. currentUserIsAdmin = false;
  16. for (var prop in my_so.data) {
  17.     trace(prop+": "+my_so.data[prop]);
  18. }
  19. //-------- trace----------
  20. //userName: Ramona
  21. //adminPrivileges: true
  22. //itemNumbers: 100,2,3,9

2 Responses to “Flash: SharedObject strange behavior”

  1. MaTT Says:

    There is some really weird stuff going on with SO in 8, I just buit this flash site for Flash 7 (www.intel.co.uk/cs), but it was crashing in 8, whenever I would set the props on my persistent scene objects, only with nested objects and arrays, then I eventually worked it out to be the SO that was crashing as I wasnt copying the data to the SO but was making a reference instead. Anyways its definetly different to flash 7, took me ages to track this one down. What you are doing here seems to me you are making a reference and doesnt seem out of the ordinary.


  2. Ghi Says:


    var so1, so2;

    var obj = new Object();
    obj.name = “occhio”;
    obj.age = 32;

    so1 = SharedObject.getLocal(”test”);
    so1.data[”man”] = obj;

    obj.name = “Ghi”;

    so2 = SharedObject.getLocal(”test”);
    if(so1.data[”man”] == so2.data[”man”])
    trace(”so1.data is equal to so2.data”);
    trace(”so1.data isn’t equal to so2.data”);

    trace(”man.name is ” + so2.data[”man”].name) // output : man.name is Ghi

Leave a Reply