Making a Save (and Load) Button
May.18, 2008 in
Flash Development
Saving is an essential part of a large game. It will keep the player coming back to your game to replay, instead of quitting because they cannot take playing anymore. This is what you will be making. Here is how to make a save button:
- On the first frame of your game, put this code: var savefile = SharedObject.getLocal(“nameOfYourGame”);
- Next, you’ll need to make a button for saving.
- Now, put this code onto the button: on (press){//when the button is pressed
savefile.data.levelNumber=_root.level;//save the variable levelNumber
savefile.data.anything=_root.anything;//save the variable anything
savefile.flush();//saves it as a cookie
} - You’ll be needing a load button now, so make one and put this code onto it: on (press){//when the button is pressed
if(savefile.data.levelNumber==undefined){//if there is no save file
_root.levelNumber=1;//the level will equal 1
}else{//otherwise
_root.level=savefile.data.levelNumber;//the level equals the number that was saved
}
} - There you go, you can save booleans too (I just chose not to). That’s all the steps of making a save and load button. You can use it for many different types of games. Use it well.
Related posts:





August 11th, 2008 at 12:39 am
anybody here know of a good site to find more info on flash games websites? I’ve got this site bookmarked and im gonna keep checking it out, but i still would like to find a site that covers flash games websites a little more thoroughly..thanks
October 11th, 2008 at 6:46 pm
Can’t get it working. Is it AS3 or AS2?
October 11th, 2008 at 10:53 pm
It should work. It’s in AS2.
November 30th, 2008 at 4:39 am
It says the load button’s script has syntax errors
November 30th, 2008 at 5:03 pm
Are you sure? I tried it in Flash 8 once again just to be sure and it works fine.
December 13th, 2008 at 4:35 am
Umm I think you need to put more detail. I know how to do physics and I know this is a lot easier, but your just not explaining it well. If your not going to explain things well put the file on here for people to look at.
December 30th, 2008 at 12:35 pm
It says that the save button
“save.flush()”
is wrong??
Why?
February 24th, 2009 at 1:39 am
to ash its savefile.flush()
March 5th, 2009 at 2:58 pm
ok so…
my action script worked but when i was testing it i clicked save then load and it diddt do anything can ya help?
March 5th, 2009 at 6:00 pm
Did you leave the frame or let the variable change, then click load? It isn’t going to seem like it’s doing anything if the data is still the same.
April 17th, 2009 at 7:53 am
Well i played a few levles pressed save quit then pressed load and the page diddnt change
July 3rd, 2009 at 10:00 pm
what are booleans
July 4th, 2009 at 9:53 am
Booleans are variables that return a value of either true or false. Check out this page on variables for more info.
August 6th, 2009 at 4:00 pm
“Scene=Scene 1, layer=Layer 3; String literal was not properly terminated
August 6th, 2009 at 4:03 pm
i keep getting the above (from my previous post) error message. I have added the code you provided
var savefile = SharedObject.getLocal(”nameOfYourGame”);
to the first scene in layer 3. Do you know why I keep getting that error message?
August 23rd, 2009 at 2:19 pm
It is AS2 and if you did it right it will work fine, try again and see if you can get it.
August 23rd, 2009 at 2:33 pm
Thanks Kevin, glad it worked for you. If anyone is having trouble, I’d be glad to help.
August 25th, 2009 at 9:52 am
Please help! I continue to get an error message when trying to use the code. The error is in the first frame of my game. The error message reads as follows:
Scene=Scene 1, layer=actions,, fr;string literal was not properly terminated var savefile = SharedObject.getLocal(“walgreensmensshavegroom”);
Director or anybody, do you know what I am doing wrong?
Thanks for all your help.
September 28th, 2009 at 8:56 am
hai, i really want to thank you for this tutorial, it works perfectly and im so excited about it, cause that means i can make really long flash game now![hahaha]
there is so many tutorial for action script 1 while i use 2 so, this tutorial is really helpful!!!
September 28th, 2009 at 3:01 pm
No problem. Glad I could help ;)
October 13th, 2009 at 10:55 am
Hi! I was just wondering if there was anyway to save the frame that the game is on and load it when you press the load button? cheers m8!
November 22nd, 2009 at 12:14 pm
is this only for scores, or can it be for progress to? If so, how?
November 22nd, 2009 at 12:19 pm
pls reply to this one, but i made a game were you get awards, and it won’t save them.
January 12th, 2010 at 4:25 pm
if you don’t put the awards and stuff on the frame, it might not work because you skipped over frames
February 28th, 2010 at 3:56 pm
you got the first code wrong, its not var savefile = SharedObject.getLocal(“nameOfYourGame”); its var savefile= SharedObject.getLocal(‘nameOfYourGame’); but it still isn’t working for me, I’m most likely messing up there. also, your load button is full of flaws.
March 1st, 2010 at 4:27 pm
This is a bit old code, I should get a new version out sometime soon. I think the quotation marks mess up Paul because of the way my site writes converts the text.
March 7th, 2010 at 6:38 am
Does the record disappear if the user clears all the Cookies on the browser?
March 7th, 2010 at 10:12 am
I believe it would Twinsen.