Professional Web Applications Themes

Saving an Array to a Shared Object - Macromedia Flash Actionscript

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...

  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. #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

  3. #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

  4. #4

    Default Re: Saving an Array to a Shared Object

    correct


    kglad webforumsuser@macromedia.com Guest

  5. #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

  6. #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

  7. #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

Similar Threads

  1. remote shared object array
    By calmchess333 in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: August 26th, 01:59 PM
  2. Convert Shared Object properties into ordered array
    By NormC_CAE in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: January 25th, 03:57 PM
  3. Shared user object array
    By alibail in forum Macromedia Flash Flashcom
    Replies: 0
    Last Post: April 20th, 08:05 PM
  4. Replies: 0
    Last Post: May 18th, 10:48 PM
  5. Replies: 5
    Last Post: September 17th, 07:54 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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