Actionscript Locally Persistent Data Object
30 May 2009
1,191 views
No Comment
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 will be taken to the page after they last left, or if they haven’t visited the site yet, the user will be taken to the 0th page.
In the real world, this code has been used to ensure that users visiting a site with a rotating campaign, saw each image and caption of the campaign on subsequent visits.










Leave your response!