00:00
00:00
Snubby
Well, aint that the dickens!

Male

Harbord

Toronto, ON

Joined on 12/4/04

Level:
21
Exp Points:
4,480 / 4,900
Exp Rank:
11,617
Vote Power:
6.24 votes
Rank:
Police Sergeant
Global Rank:
7,226
Blams:
654
Saves:
620
B/P Bonus:
12%
Whistle:
Normal
Trophies:
9
Medals:
496

Save/Load Arrays Tutorial! Did you know?!

Posted by Snubby - August 10th, 2010


Saving/loading is pretty common in flash, but a lot of people don't realize that saving/loading arrays is a different process. For example, try running the code below (make sure your flash file is called "Untitled-1")...

//////////////// cant use code tags on userpages :( //////////////////////////////////////
///
// create save data object
var saveData:SharedObject = SharedObject.getLocal ("Untitled-1.swf");

var player_inventory:Array = new Array ("hat", "sword", "gun"); // create new array

_root.saveData.data.player_inventory = _root.player_inventory; // store inventory in saved data

_root.player_inventory [0] = ["dog"]; // change original inventory array

trace (_root.saveData.data.player_inventory)
; // returns dog instead of hat for first item, even though I didn't change the saved data!
//////////////////////////////////////
///////////////////

As you can see, the code returns dog as the first element of the array, when it should return hat. The first element was changed to dog AFTER it was saved, yet the save data still says dog.

To learn how to fix this, CHECK OUT MY SAVE/LOAD TUTORIAL!


Comments

snubbyland? nice URL. ^___^

lol yeah..... i registered it when i was like 14.