Home » Archive

Articles tagged with: SharedObject

Code »

[30 May 2009 | No Comment | 1,003 views]

Flash has an easy way to save locally persistent data directly from Actionscript. Using the SharedObject Class, one can define many data points within the same object and use them like you would “cookies”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Declare a cookie name
var cookieName:String = "cookieExample";
 
//Create an object to store cookie data
var cookie:SharedObject = SharedObject.getLocal(cookieName);
 
//If the data we are looking for doesn’t exist (and it truly doesn’t exist, it’s just not 0)
if(!cookie.data.firstPageToShow && cookie.data.firstPageToShow!=0){
 
//initiate the data point
cookie.data.firstPageToShow = 0;
 
}else{
 
//increment the data point
cookie.data.firstPageToShow += 1;
}

After this code runs, if the user has visited the site before, they …