AS: Save and Load
A nice quick and easy one.
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.
Other Save/Load information:
http://www.newgrounds.com/portal/view/201218
http://www.macromedia.com/supp...ect/local_shared_object05.html
http://www.macromedia.com/supp...ctionscript_dictionary648.html
http://www.actionscripts.org/t...iate/SharedObjects/index.shtml
http://www.flashguru.co.uk/000022.php
http://www.flashmagazine.com/html/634.htm
AS: Sections
AS: Main
AS: Basic Movement
AS: Random Movement
AS: Sound
AS: Preloader