Saving an Array to a Shared Object

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default Saving an Array to a Shared Object

    Hi Folks

    (1) - Assuming I create an array as follows;

    row1=new Array("One" , "Two" , "Three");
    row2=new Array("Four" , "Five" , "Six");
    row3=new Array("Seven" , "Eight" , "Nine");

    myArray=new Array();
    myArray[0]=row1;
    myArray[1]=row2;
    myArray[2]=row3;


    (2) - I then wish to save this information to a shared object thus;

    //onbuton event
    mySharedObject = SharedObject.getLocal("savedData");
    mySharedObject.data.savedArray=myArray()
    mySharedObject.flush();

    (3) - . . . and recall it at some later stage

    //onbuton event
    mySharedObject = SharedObject.getLocal("savedData");
    trace(mySharedObject.data.savedArray[1][1]) - this should be "Five"


    ----

    but something in point two and/or three above is obviously horribly incorrect - what do I do??

    cheers - paul


    pwiop webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. remote shared object array
      Hi I'm haveing trouble with creating a array on the server side so far i have this code but i keep getting the error message this.myRSO has no...
    2. Convert Shared Object properties into ordered array
      I need to put the shared object data (that contains the client names) into an ordered array. The following is NOT useful: for (var i in...
    3. Shared user object array
      Maybe I am miss understanding this, but I have taken the sample_textchat application and have modified it slightly for my usage, I have got; ...
    4. webservice.htc and custom object array. only first object is deserialized in the result.value
      Hello I've been using webservice.htc for 6 months or so with great results. recently i came into the following problem that I am not sure how to...
    5. [newbie]saving and reading array of associative array
      i'm looking for examples of saving to file and reading back an array of associative array, in a ruby like way. saying i have something like : ...
  3. #2

    Default Re: Saving an Array to a Shared Object

    myArray is a 2-d array and you can only save variables in a shared object. so, in your shared object, you can save each element of your 2-d array (along with some identifying information) and recall and recreate your 2-d array when needed.


    kglad webforumsuser@macromedia.com Guest

  4. #3

    Default Re: Saving an Array to a Shared Object

    so I cannot save 'row1' as it is to a shared object? I have to save each element of 'row1' separately

    Then when I call each element I populate each array individually??

    paul




    pwiop webforumsuser@macromedia.com Guest

  5. #4

    Default Re: Saving an Array to a Shared Object

    correct


    kglad webforumsuser@macromedia.com Guest

  6. #5

    Default Re: Saving an Array to a Shared Object

    Hi Again

    Oddly enough you can save each row to the shared object thus

    mySharedObject.data.stageOneComplete = true;
    mySharedObject.data.savedScore1 = row1;
    mySharedObject.data.savedScore2 = row2;
    mySharedObject.data.savedScore3 = row3;
    mySharedObject.flush();

    I noticed that if the closed brackets are included after each array, ie Row1() it does not work


    on recall I just add each part to a new array thus;


    myReturnArray = new Array();
    myReturnArray[0] = mySharedObject.data.savedScore1;
    myReturnArray[1] = mySharedObject.data.savedScore2;
    myReturnArray[2] = mySharedObject.data.savedScore3;

    and to my surprise and delight it works

    no calling myReturnArray[1][1] does indeed return Five




    pwiop webforumsuser@macromedia.com Guest

  7. #6

    Default Re: Saving an Array to a Shared Object

    i didn't know that. btw, you can store your 2-d array:
    so = SharedObject.getLocal("savedData");
    so.data.savedArray=myArray;
    and retrieve it:
    so = SharedObject.getLocal("savedData");
    myA=so.data.savedArray;


    kglad webforumsuser@macromedia.com Guest

  8. #7

    Default Re: Saving an Array to a Shared Object

    Not sure how old this link is - but here is a method to store arrays into a sharedObject

    var hostName:String = "savedData";

    var testArray:Array = new Array("1","2","3");
    var tierArray:Array = new Array();
    tierArray.push({A:"Your", B:"Name"})

    var severalItems:Object = new Object();
    severalItems.item1 = "Information to Store";
    severalItems.item2 = testArray;
    severalItems.item3 = tierArray;

    var mySo:SharedObject = SharedObject.getLocal(hostName);

    mySo.data.mydata = severalItems;
    mySo.flush();

    trace(mySo.data.mydata.item1);
    trace(mySo.data.mydata.item2[1]);
    trace(mySo.data.mydata.item3[0].A);
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139