//-----Save test basic
//-----var save = SharedObject.getLocal("STB", "SB_saves");
//-----above disabled code generates a save error, and this is what forces a trace of "save failed"
var save = SharedObject.getLocal("STB");
//-----creates a variable, creates a Shared object (.SOL file) named STB
// SOL files are located in (Windows 7) C:\User\*username*\AppData\Roaming\Mac romedia\Flash Player\#SharedObjects
//Appdata is a hidden folder, so you must access it by directly editing the address
//
_global.Level = save.data.L;
_global.Lock = save.data.Lock;
if (save.data.L == undefined) {
_global.Level = 0;
}
if (save.data.Lock == undefined) {
_global.Lock = false;
}
//-----loads the .SOL file
var templock = false;
if (_global.Lock == false) {
_global.Lock = true;
world.text = ("Hello and welcome, this must be your first run (or you deleted the file) press \'+\' to increase your level, \'-\' to decrease, and \'S\', \'R\', or \'D\' to Save Reset or Delete respectively. When prompted, press \'Y\' or \'N\', and if you like, \'?\'");
} else if (_global.Lock == true && templock == false) {
templock = true;
world.text = ("Welcome Back");
}
//creates the welcome greeting, which wither gives a first timer welcome, or says welcome back
var OBJ = new Object();
OBJ.onKeyDown = function() {
KEY = Key.getCode();
//
//Level change and trace
// for the next part, make sure that you have downloaded key.as from my previous post
if (KEY == key.PLUS) {
_global.Level++;
tracelock = false;
} else if (KEY == key.MIN) {
_global.Level--;
tracelock = false;
}
if (tracelock == false) {
tracelock = true;
world.text = ("Level: "+_global.Level);
}
//
//end Level change and trace
//
//Save/Delete
//
if (KEY == key.S) {
SP = true;
DP = false
RP = false
//Save Prompt
world.text = ("Save?");
} else if (KEY == key.D) {
DP = true;
SP = false
RP = false
//Delete Prompt
world.text = ("Delete?");
} else if (KEY == key.R) {
RP = true;
DP = false
SP = false
//Reset Prompt
world.text = ("Reset?");
}
if (KEY == key.Y) {
if (DP == true) {
DP = false;
var DPT = 0;
world.text = ("Deleting . . . ");
Delete();
world.text = ("Delete Successful");
} else if (SP == true) {
SP = false;
world.text = ("Saving . . . ");
Save();
if (!save.flush()) {
world.text = ("Save Failed");
} else {
world.text = ("Save Successful");
}
} else if (RP == true) {
RP = false;
world.text = ("Resetting . . . ");
Reset();
world.text = ("Reset Successful");
}
} else if (KEY == key.N) {
if (DP == true) {
DP = false;
world.text = ("Delete Canceled");
} else if (SP == true) {
SP = false;
world.text = ("Save Canceled");
} else if (RP == true) {
RP = false;
world.text = ("Reset Canceled");
}
} else if (KEY == key.QUEMAR) {
//QUEstion MARk, see key.as
if (DP == true) {
DP = false;
world.text = ("\'Delete\' Deletes the .SOL file containing the information");
} else if (SP == true) {
SP = false;
world.text = ("Are you serious? You don\'t know what \'saving\' is? There's no help for you! >:C");
} else if (RP == true) {
RP = false;
world.text = ("\'Reset\' essentially does the same thing as delete, except that it doesn't delete the file, it just resets everything.");
}
}
//End Save/Delete
};
Key.addListener(OBJ);
function Save() {
save.data.L = _global.Level;
save.data.Lock = _global.Lock;
save.flush();
//saves/creates SOL file
}
function Reset() {
save.data.L = 0;
save.flush();
//resets Level, but not welcome boolean
}
function Delete() {
save.clear();
//deletes everything
}
Take the above script (should work in AS3, but AS2 is recommended) and paste it into the frame's AS panel of a movie, then create a dynamic text field with instance name "world"
When you start up the flash movie, it should work just like this
Press F5, and don't comment on the quirks in the save/delete area, I know there is one unused variable "DPT" and extra text that will never show, this is because this used to run on the trace console, so everything was printed out
I post this because I notice the lack of saving tutorials in flash stuff and whatnot
Now enjoy some music