PDA

View Full Version : [AS2] Saving the game?


Newbie101
07-04-2009, 11:24 PM
I want to make a button on my my game that saves the swf file to the person playing's hard drive. I want it to make it so when they come back to the game later, even if they turned their computor off, it would go to where the player last saved. (their will only be a save button after they reach a certain point.) I use Flash 8, AS 2.0
I would love some help on this subject I looked a few other places but they needed to specify more so I hope that I have given you enough info to help me out. I have no prior experience to xml or save buttons, so please make it as easy to understand as humanly posible. Thanks a bunch, Newbie101.
I really need help on this guys, I'd like an answer as fast as I can get one. Thanks again.

crosshair
07-04-2009, 11:33 PM
Look into shared objects.
Here is an example:
// Save function
function saveGame() {
mySO = SharedObject.getLocal("GAME");
mySO.data.savedanyvar = anyvar;
mySO.flush();

for (a in mySO.data) {
trace(a+": "+mySO.data[a]);
}
}

// Load function
function loadGame() {
mySO = SharedObject.getLocal("GAME");

anyvar = mySO.data.savedanyvar;

for (a in mySO.data) {
trace(a+": "+mySO.data[a]);
}
}

// Delete function
function deleteGame() {
mySO = SharedObject.getLocal("GAME");
for (a in mySO.data) {
delete mySO.data[a];
}
mySO.flush();
delete mySO;
mySO = SharedObject.getLocal("GAME");
for (a in mySO.data) {
trace(a+": "+mySO.data[a]);
}
}
Rename anyvar to what your var you want to be saved is.
If you want me to give a more in depth explanation just say so :)

Hope it helps.

Newbie101
07-04-2009, 11:39 PM
This probably a stupid question, but can I make the var a frame so it starts at that frame?

crosshair
07-04-2009, 11:51 PM
You could make a variable and set it at each frame and make it gotoAndStop to the value of the var.

finaiized
07-05-2009, 12:38 AM
Not really a contribution to the topic, but thanks for the information. I've found loads of image from Adobe Docs on SharedObject() =)

Newbie101
07-05-2009, 02:13 AM
Thanks a lot Crosshair! Now I can make my save file.

crosshair
07-06-2009, 02:06 AM
No problem, i remember how long i spent looking up stuff like this :(