问题
I have this flash game that I've been working on that works out of the browser, and I'm looking to get it to save it's progress.
I've seen multiple flash games that have accomplished this, and It appears as though they've done this client-side, and I'd like to do the same.
My game consists of 1 mxml
file and a number of .as
files and I compile it from the command line using flex sdk.
What do I have to do to be able to save save my game's data?
回答1:
As others have mentioned, SharedObject is the tool you'll use for this.
The basics of this are to initialize a reference to a SharedObject
using its static method .getLocal()
first:
var mySaveData:SharedObject = SharedObject.getLocal("SomeSaveName");
The String given to this method should not contain spaces.
Once you've done this, you'll be able to use mySaveData.data, which is basically a simple object that you can attach properties to on the fly (it's dynamic):
mySaveData.data.levelsComplete = 2;
Once you've done this, you'll be able to reference that value later on using the same process:
trace( mySaveData.data.levelsComplete );
回答2:
For simple stuff you can use SharedObject
回答3:
One way is to use flash's SharedObject to save values in to a 'flash cookie' on the client. Example can be found here: Actionscript 3 saving currentframe location to local hard drive?
来源:https://stackoverflow.com/questions/14595431/how-to-i-make-my-flash-as3-game-save-progress