Shared Object
        by Jeremy Moseley : 21 July 2004

This tutorial will teach you how to use the Shared Object in Actionscript 2.0. The Shared Object is like a cookie, but it does not require a browser or server-side scripts to use. It is for Flash only and can be loaded instantaneously from the users machine. It is the most efficient way to save information about your users so that they can use it at a later date.

Here is an example using the Shared Object:

[ This is an example of the Shared Object ]

Here is How
These steps will show you how to easily use the Shared Object.

  1. First, create or open a Flash document.

  2. Now open the Actions Panel for the first frame (or whenever you want to load the data)

  3. Create a Shared Object using the getLocal method:

user_so = SharedObject.getLocal("user");
//user_so is the name of our sharedObject that we are creating. this can be any name
//"user" is the actual name of the file we are loading from the clients harddrive.
//This can be anything, but you must use the same name to get the same data
  1. Now that we have our Shared Object we will check to see if there is data already in it:

if( != undefined) {
//data exists
//do actions
} else {
//data does not exists
//do actions
  1. If there is no data we can easily insert it by assiging values to the .data property: = "insert value here"; = "insert value here"; = "insert value here";
// actually holds the information gotten from the user.
//easily store more than one value per object simply by assigning them names and values
// is a value from the Shared Object.
//.tname can be anything and is simply used to reference the value
  1. If there is data we can access it by simply using an assignment command:

name_txt.text =;
address_txt.text =;
other_txt.text =;
//name_txt is just a dynamic text field that will display our data
//you can load data from an Shared Object as soon as it has been assigned
//example: = "this is my name";
user_name =;
//this will return "this is my name"
  1. If you would like to store information in the Shared Object but not have is stored, assign it as another property of the Object:

user_so.string = "this won't be saved";
user_so.another = "neither will this";
//neither of the values above will be saved
//Flash only saves the values that are in the Shared property
  1. To delete a Shared Object just use the clear method:

//this will delete the Shared Object
//after you call this command the Shared Object will no longer exist
  1. You do not need to worry about saving the information as Flash will do this automatically, however you can still use the flush method:

//this will save the info in the user_so object
//however Flash will still save changes automatically when it closes

Back Track
Well done for making it this far. Here we have a little review.

  1. First, you Learned to create a Shared Object using the getLocal method.

  2. You learned to check for data using an if statement.

  3. You learned to add and delete data.

  4. You learned to delete the Shared Object with the clear method.

  5. Finally, you learned to save the shared Object with the flush method.

I have included the source for the example above in this .ZIP file:

Download ZIP

I hope this tutorial has helped you out and will allow you to create better and more badass things in Flash in the future. Remember, if you have any problem at all you can always post at the KirupaForums and somebody (maybe even me) should be able to give you a hand. Thanks for reading.

Have Fun!

Jeremy Moseley - Jerez_z
My Forum


SUPPORTERS:'s fast and reliable hosting provided by Media Temple.