PDA

View Full Version : Save and Load


CarMan1390
12-26-2007, 11:58 PM
What?
Flash allows you to store a 'cookie' on the local machine. These are .sol files, and on WinXP, they can be found at:
C:/Documents and Settings/Username/Application Data (hidden)/Macromedia/Flash Player/
--------------------------------------------
Loading
A simple example: Score and Level.
This example will autoload old score/level when the game is started
Add this at the start of your main timeline:
//Specify the save file to use
var savefile = SharedObject.getLocal("yourgamename");
//Grab the level and score held in the file, and assign them to variables
_root.oldscore = savefile.data.score;
_root.oldlevel = savefile.data.level;
//If they don't exist, (ie first run), set variables to zero
if(savefile.data.score==undefined){
_root.oldscore=0;
_root.oldlevel=0;
}
Same thing, but on a LOAD button
on (press){
var savefile = SharedObject.getLocal("yourgamename");
if(savefile.data.score==undefined){
_root.score=0;
_root.level=0;
}else{
_root.score=savefile.data.score;
_root.level=savefile.data.level;
}
}
------------------------------------------
Saving
Assume that your game score is held in the variable "_root.score", and the current level is "_root.level".
Now put a SAVE button where you want to allow saving, and add these actions:
on (press){
savefile.data.score=_root.score;
savefile.data.level=_root.level;
savefile.flush();
}
-----------------------------------------
And that's it. You can send text and numbers to the savefile, using script variables or text input. Be wary of hexadecimal colour values, I've had problems with them.

-Denvish from Newgrounds (http://denvish.newgrounds.com)

Mattimos
12-31-2007, 06:49 AM
Another great tutorial! Thanks CarMan!

cooldog124
01-01-2008, 01:10 PM
ya wow thanks

RJMasters
02-05-2008, 02:03 AM
Question for ya CarMan...

Can someone open the .sol file and see the saved info? I wonder because if someone can do that, isn't possible for them to open it and then change the info like change their score from 200 to 200000 or something like that.

I opened a few on my machine to take a look and many of them looked pretty jumbled up, but I could read many of the vars, found my gamer name in a cpl of them.

Is there anything we should guard against if we use this type of saving style? Thanks for your time and putting out this cool Tutorial. I have a rather involved game with alot of vars that need saving. I would like to know before I walk down this path what the potential will be for people to hack and cheat the game by altering this .sol file. any insight would be appreciated. Thanks.

RJ

itachy
03-16-2008, 05:48 PM
Another great tutorial! Thanks Car

SupaFruit
03-21-2008, 12:34 PM
Once again, nice tutorial.