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