Flash CS5.5 and AS3 – How to save local data to a Flash Shared Object (Flash Cookie)

Create a shared object (Flash Cookie) in Flash to save data for later retrieval. These shared objects are saved with a SOL file extension.

Here are two ways you can find them.

Run the ‘Analyze’ feature of ‘CCleaner’   (You can get this product at http://www.piriform.com/ccleaner)

Do a scan using the program Flashcookiesview.   (You can get this product at http://www.nirsoft.net/utils/flash_cookies_view.html)

I will call my shared object (or file) myLocalData.

var myLocalData:SharedObject =SharedObject.getLocal("myLocalData");

To set data in a shared object, define any object name of you want after the class member, data, and assign it a value. The object can be a string, number, or even an object.

myLocalData.data.name= "James";
myLocalData.data.score = 80;

The shared object is written from memory to the hard drive when the flash movie ends. You can force the shared object to be written manually using the flush() command.

You can read the shared object from memory at any time while the flash movie is active.

Here is an example by using a trace.

trace("Name = " + myLocalData.data.name);
trace("Score = " + myLocalData.data.score);

An object would be read like this:

trace("someobject = " + getlocal.(“TheObject”);

You can check whether the data exists like this:

If (myLocalData.data.name == null)

You can delete a shared object like the following:

MyLocalData.clear();

You can delete just the object variables of a shared object using a loop:

For (var MyObjectVariable in MyLocalData.data)
{
 deleteMyLocalData.data(MyObjectVariable);
}

Leave a Reply

Your email address will not be published. Required fields are marked *