Flash Player 6.
Shared objects are powerful: They offer real-time data sharing between objects that are persistent on the user's computer. You can consider local shared objects as cookies.
You can use local shared objects to maintain local persistence. For example, you can call SharedObject.getLocal() to create a shared object, such as a calculator with memory, in the player. Because the shared object is locally persistent, Flash saves its data attributes on the user's computer when the SWF file ends. The next time the SWF file runs, the calculator will display the values it had when the SWF file ended. Alternatively, if you set the shared object's properties to null before the SWF file ends, the calculator opens without any prior values the next time the SWF file runs.
To create a local shared object, use the following syntax:
// Create a local shared object
var so:SharedObject = SharedObject.getLocal("foo");
Local shared objects are always persistent on the client, depending on available memory and disk space.
By default, Flash can save locally persistent remote shared objects as large as 100K. When you try to save a larger object, Flash Player shows the Local Storage dialog box, which lets the user allow or deny local storage for the domain that is requesting access. (Ensure that your Stage size is at least 215 x 138 pixels; this is the minimum size Flash requires to display the dialog box.)
If the user clicks Allow, the object is saved and SharedObject.onStatus is invoked with a code property of SharedObject.Flush.Success; if the user clicks Deny, the object is not saved and SharedObject.onStatus is invoked with a code property of SharedObject.Flush.Failed.
The user can also specify permanent local storage settings for a particular domain by right-clicking (Windows) or Control-clicking (Macintosh) while a SWF file is running, selecting Settings, and then opening the Local Storage panel.
You can't use ActionScript to specify local storage settings for a user, but you can display the Local Storage panel for the user by using System.showSettings(1).
The following list summarizes how the user's disk space choices interact with shared objects:
SharedObject.flush() commands issued for the object return false.
SharedObject.flush() commands issued for the object return "pending", and the player asks the user if additional disk space can be allotted to make room for the object.
SharedObject.flush() returns true if the object fits within the specified amount of space. If more space is needed, SharedObject.flush() returns "pending", and the player asks the user if additional disk space can be allotted to make room for the object.
Additionally, if the user selects a value that is less than the amount of disk space currently being used for locally persistent data, the player warns the user that any locally saved shared objects will be deleted.
Note: There is no size limit in Flash Player that runs from the authoring environment.
| Method | Description |
|---|---|
SharedObject.clear() |
Purges all the data from the shared object and deletes the shared object from the disk. |
SharedObject.flush() |
Immediately writes a locally persistent shared object to a local file. |
SharedObject.getLocal() |
Returns a reference to a locally persistent shared object that is available only to the current client. |
SharedObject.getSize() |
Gets the current size of the shared object, in bytes. |
| Property | Description |
|---|---|
SharedObject.data |
The collection of attributes assigned to the |
| Event handler | Description |
|---|---|
SharedObject.onStatus |
Invoked every time an error, warning, or informational note is posted for a shared object. |
For information on creating local shared objects, see SharedObject.getLocal().
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001664.html
Comments
Zerg said on Feb 26, 2005 at 4:11 AM : dericos said on Jul 26, 2005 at 12:39 PM : michieldb said on Aug 26, 2005 at 3:28 AM : Kevin_H said on Aug 31, 2005 at 9:22 AM : kev - signals.co.uk said on Sep 7, 2005 at 9:20 AM : kev - signals.co.uk said on Sep 7, 2005 at 9:21 AM : No screen name said on Feb 20, 2006 at 7:44 AM :