As2 or As3? The method is going to be slightly different although the concept is still the same. To save data to a local cookie file, you need to create a Shared Object Variable, name it, then you just store and recall data from that shared object.
- Code: Select All Code
import flash.net.SharedObject;
public var gameData:Array;
public var saveData:SharedObject;
saveData = SharedObject.getLocal("com.mySaveFileName","/");
Then you create a new array in the game to hold all your save data, and copy it to the 'data' attribute of your save cookie. In this example, I used a new array on the shared object called "mainSlot" - if, for example, you wanted multiple saves (like in LoKvG), you could add other arrays to save the other data (like mainSlot, secondSlot, thirdSlot etc etc).
- Code: Select All Code
saveData.data.mainSlot = new Array();
gameData = new Array();
gameData[0] = theFirstVariableIWantToSave;
gameData[1] = theSecondVariableIWantToSave;
gameData[2] = theThirdVariableIWantToSave;
gameData[3] = theEtcEtcEtcVariableIWantToSave;
saveData.data.mainSlot = gameData;
saveData.flush();
To load the data later, you just do the opposite: take the saveData.data.mainSlot Array and copy it back to your variables:
- Code: Select All Code
gameData = saveData.data.mainSlot;
theFirstVariableIWantToSave = gameData[0];
theSecondVariableIWantToSave = gameData[1];
theThirdVariableIWantToSave = gameData[2];
theEtcEtcEtcVariableIWantToSave = gameData[3]
Make sense? If you are ever looking for the 'physical' copy of the save file, it will be in your adobe system folder under the name you stuck up in the first part of the code ("com.mySaveFileName"). There are some other ways to do it, like actually making a text file and loading/saving to it, but for web based games, cookies are just easier and no fuss no muss.