Shared Object / Flash Cookie in ActionScript 3

Sometimes you may want to store information on the clients machine.  You can do this using a Flash Shared Object, this is basically a Flash Cookie.  A Flash Cookie is actually a little better than a normal cookie.  Flash Cookies are a little more secure and cannot be deleted like your browser's normal cookies are.  Very few users know how to delete them, which is pretty cool for us Flash Developers.

Here is how you set a SharedObject in ActionScript 3:

var __so:SharedObject = SharedObject.getLocal("theactionscripter");
__so.data.favoriteWebsite = "http://www.theactionscripter.com";
__so.data.userId = "123";
__so.flush(); //Immediately writes a locally persistent shared object to a local file.
 

Here is how you get a SharedObject in ActionScript 3:
var __so:SharedObject = SharedObject.getLocal("theactionscripter");
trace(__so.data.favoriteWebsite ); //http://www.theactionscripter.com
  
Here is how you clear a SharedObject in ActionScript 3:
var __so:SharedObject = SharedObject.getLocal("theactionscripter");
__so.clear();
 

View Demo of SharedObject.



Source Code

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Enter the above security code (required)

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.