Search code examples
actionscript-3flashapache-flexflex3mxml

how to I make my flash AS3 game save progress


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?


Solution

  • 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 );