Friday, January 16, 2009
Saving Local Data
Local data is used to save data into the user's machine such as score,level number,..etc.
On the top of this post I made a simple counter that counts how many times did the visitor visit my blog!
Here is the code for it
__________________code start____________________
var count:int;//the counter variable
var myLocalData:SharedObject = SharedObject.getLocal("mygamedata");//making a local shared object
var myData:String=""+myLocalData.data.storedInfo;//adding the info in the shared object to myData
if(myData=="undefined")//if there is no stored data before in the shared object it will return undefined
myLocalData.data.storedInfo=1;//store one because this is the 1st visit
else//if this is not the 1st visit increment the value of the shared object by 1
++myLocalData.data.storedInfo;
count=myLocalData.data.storedInfo;//assign the value of the shared object into count
counter.text=""+count;//write the vaalue of count
__________________code end____________________
Here is the source file
Enjoy it!!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment