View Full Version : Saving and lodaing flash game
overlordlink
June 20th, 2010, 02:38 AM
Ok well.... my idea here is to have a save button that saves you data, or an auto save function either one. Then when you start your game, have a load button that loads the data and takes you to the corresponding level.
For the save button code I have this.
on(release){
savefile.data.levelnum= _root.levelnum;
savefile.flush();
}
And the load button code is.
on(release){
var savefile = SharedObject.getLocal("test");
_root.levelnum = savefile.data.levelnum;
}
if (savefile.data.levelnum == undefined ){
_root.gotoAndStop("level1")
Now the only problem with this is I don't know how to actually implement it. For instance it saving the levelnum equal to 4 then when it loads having it go to the fourth level.
Geki
June 20th, 2010, 06:05 PM
Use a switch/case statement. http://www.tech-recipes.com/rx/2369/as3_switch_case_statement_syntax/
overlordlink
June 20th, 2010, 07:27 PM
Use a switch/case statement. http://www.tech-recipes.com/rx/2369/as3_switch_case_statement_syntax/
well that doesn't really help that as3 and I am using as2.
therobot
June 20th, 2010, 11:40 PM
Here is how a switch works in as3:
var someVariable:String = "something";
switch(someVariable)
{
case "something" :
trace("it's something");
break;
case "somethign else" :
trace("it's something else");
break;
default :
trace("dunno!");
break;
}
Here is how a switch works in as2:
var someVariable:String = "something";
switch(someVariable)
{
case "something" :
trace("it's something");
break;
case "somethign else" :
trace("it's something else");
break;
default :
trace("dunno!");
break;
}
overlordlink
June 21st, 2010, 01:02 AM
So if I have this right it would go like this?
var savefile = SharedObject.getLocal("test");
switch(savefile)
{
case "_root.levelnum = 1" :
trace("level1");
break;
case "_root.levelnum = 2" :
trace("level2");
break;
default :
trace("level1");
break;
}
therobot
June 21st, 2010, 02:15 PM
the switch lets you compare many variables, not just strings.
var someVariable:String = 1234;
switch(someVariable)
{
case 2 :
trace("the number is 2!");
break;
case 1234 :
trace("the number is 1234!");
break;
default :
trace("dunno!");
break;
}
you'd probably be storing the level to load so you could do something like this:
var levelToLoad = 1;
switch(levelToLoad)
{
case 1 :
trace("load level 1!");
break;
case 2 :
trace("load level 2!");
break;
default :
trace("don't know which level to load!");
break;
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.