If you don't care if the saved info is human readable (or prefer it that way), a good way to do this is to use serialized objects in either a save file, or a shared object.
The process is pretty similar regardless of which storage mechanism used. Here is an example.
First, make a global var for your shared object (probably at the start of your application):
var sharedObj:SharedObject = SharedObject.getLocal("MySaveData");
//if data exists in the shared object, load it or do something with it
if(sharedObj.data.userName){
trace("Hello " + saveData.userName);
}
Later, when you want to save some data:
sharedObj.data.userName = "fflinstone";
sharedObj.data.wrongAttempts = 5;
//etc for other properties you want to add
sharedObj.flush(); //write the data to file
Keep in mind, that any non-primitive class you use, must be registered to unserialize them.
So, if you wanted to save a type of object that required an import statement (like a Rectangle
for instance) you'd have to register that by doing:
flash.net.registerClassAlias("flash.geom.Rectangle", Rectangle); //you only have to have this once in your whole application, usually at the start of your program
Alternatively, you could create a model for your save data (a custom class).
To do it that way, create a new class file (in AnimateCC, go file -> new -> actionscript 3.0 class
- Give it the name SaveData
). Make the content of the file look like this:
package {
public class SaveData {
public var userName:String;
public var wrongAttempts:int;
public var correctAttempts:int;
public var timeToCompletion:Number;
}
}
Add whatever properties you want to store as public vars as shown.
Then, register the class so it can saved in a shared object (you can do this at the start of your app)
flash.net.registerClassAlias("SaveData",SaveData);
Then create a global save data variable:
var saveData:SaveData;
And load in the data:
saveData = sharedObject.data.saveData as SaveData;
if(saveData){
//load your saved data
}else{
saveData = new SaveData();//create a new one since one didn't previously exist
}
During you app, assign values to the save data object:
saveData.wrongAttempts++;
Then later save it:
sharedObject.data.saveData = saveData;
sharedObject.flush();