# Loading data from sor into an array?

**URL:** <https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390>\
**Category:** Uncategorized\
**Created:** [June 17, 2004, 1:54pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390 "2004-06-17T13:54:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boondogger](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Boondogger](https://forum.kirupa.com/u/Boondogger)\
**Post date:** [June 17, 2004, 1:54pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390/1 "2004-06-17T13:54:46Z")

</div>

I have a multi-dimensional array and I need to save its data into my shared object file and then load it back into the array again. Given that the array has loads of elements I don’t want to do it variable by variable. I saved it out by sending the information out using a for loop and putting in & to spearate the data.  
Next I load it up into a variable and convert it to a string. Now I want to read the string and load it up into the array again, incrementing the array every time it hits &. The code is below for this. It is supposed to load up the contents of element [x] [3] :

function loadGame() {  
mysavegame = SharedObject.getLocal(“flashcookie”);  
if (mysavegame.data.datastring == undefined) {  
// No object exists  
trace(“No Saved Game”);  
} else {  
trace(“Loaded Game”);  
bigstring = mysavegame.data.datastring;  
bigstring.toString();  
trace(bigstring); //traces out my data separated by &  
k = 0;  
for (i=0; i\<bigstring.length; i++) {  
if (bigstring.charAt(i) != “&”) {  
datum += bigstring.charAt(i);  
myArray[k][3] = datum;  
i++;  
} else {  
i++;  
k++;  
trace("myArray [k] [3] is "+(myArray[k][3]));  
}  
}  
}  
}  
trace(myArray[1][3]);// traces as undefined!!

There’s probably a much more sensible way to do this but I haven’t been doing actionscript long. The trace from this is weird. The first element always seems to get missed and so do the last four. Furthermore when I try to trace the data outside of the load function it traces as undefined. Why?

This is the Trace:

Loaded Game  
392000&467200&199800&321600&297600&198400&195000&201600&139200&162000&171600&102600&106000&  
myArray [k] [3] is 467200  
myArray [k] [3] is 199800  
myArray [k] [3] is 321600  
myArray [k] [3] is 297600  
myArray [k] [3] is 198400  
myArray [k] [3] is 195000  
myArray [k] [3] is 201600  
undefined

Any ideas out there?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 3:04pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390/2 "2004-06-17T15:04:34Z")

</div>

Well I believe that you can just save an array to a SharedObject  
So no need to turn it in to a string.

```auto

 loadGame = function () {
     savedGame_so = SharedObject.getLocal("flashcookie");
     if (savedGame_so.data.multi_array == undefined) {
         trace("No Saved Game");
     } else {
         trace("Loaded Game");
         _root.multi_array = savedGame_so.data.multi_array;
         trace(_root.multi_array);
     }
 };
 saveGame = function () {
     savedGame_so = SharedObject.getLocal("flashcookie");
     if (savedGame_so.data.multi_array == undefined) {
         trace("Saving Game");
         savedGame_so.data.multi_array = _root.multi_array;// easy
         trace(savedGame_so.data.multi_array);
     } else {
         trace("There Is Already A Game Saved");
     }
 };
 

```

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 8:13pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390/3 "2004-06-17T20:13:27Z")

</div>

Thanks for your suggestion. When I tried this the trace message I got was as follows:

Loaded Game  
[object Object], [object Object], etc. etc.

Which looks a bit odd. Why doesn’t the trace command trace what data was loaded?

But the data seems to have loaded fine, so thanks a lot for that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 8:45pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390/4 "2004-06-17T20:45:01Z")

</div>

Thats because flash does not list out all the info for each array, if you try to trace an array you will get that [object],[object] stuff. You need to get used to using the debugger for flash set some break points to better understand whats going on. It will make things much more simple. If you are still having problems after a while I can help you out.

-Boozy

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 17, 2004, 9:57pm UTC](https://forum.kirupa.com/t/loading-data-from-sor-into-an-array/113390/5 "2004-06-17T21:57:20Z")

</div>

C:-) Cheers Boozy. I may just do that!

Boondogger
