Table of Contents

SharedObject.data Property Flash 6

container for data stored locally or sent to Comm Server read-only
theSharedObj.data

Description

The data property contains a generic object whose properties are saved to disk when the movie is unloaded from the Player or when SharedObject.flush( ) is invoked. If theSharedObj is a local SharedObject that has been retrieved from disk, the properties of data contain the values last saved. Properties can contain the following datatypes: number, string, boolean, undefined, null, array, and object (custom classes plus XML and Date). Other built-in ActionScript classes and objects (such as MovieClip and Function) cannot be stored in a SharedObject.

For a value to be saved, it must be stored within a property of data. Properties attached directly to theSharedObj are not saved to disk, while assignments to data itself are ignored completely. Therefore, you should attach properties to theSharedObj.data, not directly to theSharedObj itself, and don't try to overwrite the data property. For example:

timeTracker_so = SharedObject.getLocal("punchClock");
   
timeTracker_so.data.time = new Date();  // CORRECT! Will be saved.
timeTracker_so.time = new Date();       // INCORRECT! Will not be saved.
timeTracker_so.data = new Date();       // INCORRECT! Will be ignored.

Properties of data can be removed with the delete operator. For example:

delete theSharedObj_so.data.score;

Assigning a value of null or undefined to a property removes the value, but the property itself still exists and will still show up in a for-in loop and be saved to disk, albeit as an empty value.

The default maximum amount of data that can be saved to disk is 100 KB per domain. For details, see SharedObject.flush( ). To determine the size of the properties assigned to data, use SharedObject.getSize( ).

When a property of data is an object that belongs to a custom class, the save/retrieve process disconnects the object from its class. Methods and properties accessed via the prototype chain will not be available to the object after it is retrieved. However, we can use Object.registerClass( ) to associate the object with an identifier used to restore its class at retrieval time. For details, see Object.registerClass( ).

Example

The following code retrieves a local SharedObject named "gameData". It then assigns a property, player1score, and saves the object by invoking flush( ):

// Create/retrieve the SharedObject.
gameData_so = SharedObject.getLocal("gameData");
// Make a property to save.
gameData_so.data.player1score = 2600;
// Attempt to save the SharedObject.
gameData_so.flush();

See Also

Object.registerClass( ), SharedObject.flush( ), SharedObject.getLocal( ), SharedObject.getSize( )


Table of Contents