Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > SharedObject | |||
Object
|
+-SharedObject
public dynamic class SharedObject
extends Object
The SharedObject class is used to read and store limited amounts of data on a user's computer. Shared objects offer real-time data sharing between objects that are persistent on the user's computer. Local shared objects are similar to browser cookies.
Here are three possible uses of shared objects:
Local shared objects maintain local persistence. For example, you can call SharedObject.getLocal() to create a shared object that contains the high score in a game. Because the shared object is locally persistent, Flash saves its data attributes on the user's computer when the game is closed. The next time the game is opened, the high score from the previous session is displayed. Alternatively, you could set the shared object's properties to null before the game is closed. The next time the SWF file runs, the game opens without the previous high score.
To create a local shared object, use the following syntax:
var so:SharedObject = SharedObject.getLocal("userHighScore");
so.data.highScore = new Number();
so.flush();
In the example, the shared object is explicitly flushed, or written to a disk. When an application closes, shared objects are automatically flushed; however, it is shown here to demonstrate the step of writing data to a disk.
Local disk space considerations: Local shared objects can be very useful, but they have some limitations that are important to consider as you design your application. Sometimes your SWF files may not be allowed to write local shared objects, and sometimes the data stored in local shared objects can be deleted without your knowledge. Flash Player users can manage the disk space that is available to individual domains or to all domains. When users lower the amount of disk space available, some local shared objects may be deleted. Flash Player users also have privacy controls that can prevent third-party domains (domains other than the domain in the current browser address bar) from reading or writing local shared objects.
Note: Local content can always write third-party shared objects to disk, even if writing of shared objects to disk by third-party domains is disallowed.
Adobe recommends that you check for failures that are related to the amount of disk space available and to user privacy controls. Perform these checks when you call getLocal() and flush():
SharedObject.getLocal() -- This method returns null when the user has disabled third-party shared objects and the domain of your SWF file does not match the domain in the browser address bar.
SharedObject.flush() -- This method returns false when the user has disabled shared objects for your domain or for all domains. It returns "pending" when additional storage space is needed and the user must interactively decide whether to allow an increase.
If your SWF file attempts to create or modify local shared objects, make sure that your SWF file is at least 215 pixels wide and at least 138 pixels high (the minimum dimensions for displaying the dialog box that prompts users to increase their local shared object storage limit). If your SWF file is smaller than these dimensions and an increase in the storage limit is required, SharedObject.flush() fails, returning "pending" but then calling your SharedObject.onStatus handler with a result of "SharedObject.Flush.Failed".
Availability: ActionScript 1.0; Flash Player 6
getLocal (SharedObject.getLocal method), flush (SharedObject.flush method), onStatus (SharedObject.onStatus handler)
|
Modifiers |
Property |
Description |
|---|---|---|
|
|
The collection of attributes assigned to the |
Properties inherited from class Object constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)
|
Event |
Description |
|---|---|
|
Invoked every time an error, warning, or informational note is posted for a shared object. |
|
Modifiers |
Signature |
Description |
|---|---|---|
|
|
clear |
Purges all the data from the shared object and deletes the shared object from the disk. |
|
|
Immediately writes a locally persistent shared object to a local file. |
|
|
|
getLocal |
Returns a reference to a locally persistent shared object that is available only to the current client. |
|
|
Gets the current size of the shared object, in bytes. |
Methods inherited from class Object
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00002118.html