FreshNova - Home

Friday 30th of July 2010

Home Flash Tutorials Saving Local Data
Saving Local Data PDF Print E-mail
Written by Administrator   
Thursday, 22 January 2009 19:53

Ever wanted to save some information about a user like his level number, or last high score, or any other information. Well ActionScript provides a simple way to achieve this. Local data is used to save data into the user's machine such as score,level number,..etc. Below is the simplest example of saving local data on to a users computer.

 

Here is a simple counter that counts how many times did you visit this article on FreshNova!

 

 

Read on to see the source code. The source code is well documented so I believe it is not too hard to understand.


 Source Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//the counter variable
var count:int;
//making a local shared object
var myLocalData:SharedObject = SharedObject.getLocal("mygamedata");
//adding the info in the shared object to myData
var myData:String=""+myLocalData.data.storedInfo;
//if there is no stored data before in the shared object it
//will return undefined
if(myData=="undefined")
//store one because this is the 1st visit
myLocalData.data.storedInfo=1;
//if this is not the 1st visit increment the value of the
//shared object by 1
else
++myLocalData.data.storedInfo;
//assign the value of the shared object into count
count=myLocalData.data.storedInfo;
counter.text=""+count;//write the vaalue of count

 

You will find the source file in the attachments below.   Enjoy it!!
Attachments:
FileFile sizeLast Modified
Download this file (LocalDataCounter.fla)LocalDataCounter.fla48 Kb07/02/09 20:36

Comments

avatar Samuel Thompson
0
 
 
Hi, thank you for the tips, they are great. ActionScript is a good tool to save some information about a user, which is often important to me. You just gave me a great idea. Thanks for the post, it's really helpful.
I usually look for some information on similar topics at http://www.torrentbasket.com/ torrent SE but your website is really a good source of information.
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Cancel
Name *
Email (For verification & Replies)
Code   
ChronoComments by Joomla Professional Solutions
Submit Comment
Last Updated on Tuesday, 10 February 2009 10:54
 

Archive

 

Categories


Copyright © 2009 FreshNova, by Talha Kalim and Waleed Al-Bahrawy