SharedObject - Flash Cookies

Tue Feb 16 06:04:06 2010

For anyone making applications using ActionScript 3.0, SharedObject is an absolute must! It allows data to be stored inside the flash player itself, meaning applications you create do not have to reply on browser cookies, and thus there is no worry of browser cookies being deleted or the hassle of writing a program in something like PHP to store your data on a database for example... although that may be a little more efficient especially if you are writing something that stores long-term data.

To use SharedObject, all you have to do is create a variable and datatype it to SharedObject. Don't forget to import if you haven't already. Take at the variable below.

var myData:SharedObject = SharedObject.getLocal("data"); 
By setting the SharedObject it will automatically be created by the Flash Player. There are no further steps involved in creating this data so it's quick and easy.

The SharedObject will accept all kinds of data including numbers, strings, arrays, etc. When data is not already set inside your SharedObject, it will return undefined. For example, I have yet to set any data in the variable 'myData' that I created earlier and so if I tried to trace any data I would get undefined.

trace("My data : "; //traces My data : undefined 
If I were now to actually set data and then trace it, SharedObject would return that data back to me. = "I set this."; 
trace("My data : "; //traces My data : I set this

Additionally, you can clear any data set by calling the clear() method on your variable.

trace("My data : "; //traces My data : undefined

Naturally, that is not all there is to know about SharedObject, but it should be enough to get those who are not yet savvy about this on their feet. As a side note, this has been around for quite sometime and those game creators who haven't yet checked this out should definitely do so.

← back

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by

Click the app icons to see more info