Object | +-SharedObject public dynamic class SharedObject extends Object
The Flash Lite version of the SharedObject class allows Flash SWF files to save data to the device when it is closed and load that data from the device when it is played again. Flash Lite shared objects store a set of name-value pairs to the device.
Note: The name "SharedObject" is derived from the Flash SharedObject class. The Flash version of this class allows multiple Flash SWF files to share their saved data. However, the Flash Lite version of the SharedObject class does not support sharing data between different Flash SWF files.
In Flash Lite, a SWF file is considered to be a different version if it was modified from the original version, even if it has the same name. This is different than in Flash Player, where a SWF file is considered to be the same if its URL and name are the same, even if the SWF file was modified. In Flash Lite, two different versions of a SWF file can't access each other's shared objects.
To maintain consistency with the Flash platform, the same ActionScript construct and calling conventions are used for the Flash Lite player.
The following examples describe the potential of using shared objects:
Note: Because space is limited on mobile devices, the data is not completely persistent; in some situations, the platform could delete the oldest data from the device.
To create a local shared object, use the following syntax:
var so:shared object = shared object.getLocal("mySharedObject");
Reading and writing data on a handset can be slow. To ensure that data is immediately available when the application requests it from the device, Flash Lite 2.0 requires you to set up a listener. The player invokes the listener when the device has loaded the shared object's data. Methods that access the SharedObject instance returned by the call to getLocal() should wait until the listener is invoked before attempting any operations.
In the following example, a SWF file creates a listener function named Prefs and then creates a shared object. The player calls the loadCompletePrefs function when the data is available.
function loadCompletePrefs (mySO:SharedObject) {
if (0 == mySO.getSize() )
{
// If the size is 0, we need to initialize the data:
mySO.data.name = "Sigismund";
mySO.data.email = "siggy@macromedia.com";
}
else
{
// Trace all the data in mySO:
trace( "Prefs:" );
for (var idx in mySO.data) {
trace( " " + idx +": " + mySO.data[idx] );
}
}
}
SharedObject.addListener( "Prefs", loadCompletePrefs );
// We can now create the shared object:
var Prefs:SharedObject = SharedObject.getLocal("Prefs");
When the player has notified the listener that the data is available, the application can use the shared object returned from the call to the getLocal() method in the same way a shared object is used in Flash. The application can add, modify, or remove properties while the content is playing. When the content is unloaded, the shared object might be written to the device; however, to guarantee that the shared object will be written to the device, the application must force a write operation by calling the flush() method.
Flash Lite shared objects are available only to locally stored SWF files. SWF files playing back in a network-enabled browser cannot use Flash Lite shared objects.
The total amount of storage for Flash Lite shared objects per SWF file is limited by the deviceto a predetermined size. You can determine this size by using the SharedObject.getMaxSize() method.
Note: Remote shared objects are not supported in Flash Lite 2.0.
flush (SharedObject.flush method), onStatus (SharedObject.onStatus handler)
|
Modifiers |
Property |
Description |
|---|---|---|
|
|
The collection of attributes assigned to the data property of the object. |
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 |
|---|---|---|
|
static |
addListener(objectName:String, notifyFunction:Function) : Void |
Creates an event listener that the Flash Lite player invokes when the player has loaded the shared object data from the device. |
|
|
clear() : Void |
Purges all the data from the shared object and deletes the shared object from the disk. |
|
|
Writes shared object to a local, persistent file. |
|
|
static |
getLocal(name:String) : SharedObject |
Returns a reference to a locally persistent shared object that is available only to the current client. |
|
static |
getMaxSize() : Number |
Returns the total number of bytes the SWF file can use to store mobile shared objects on the device. |
|
|
Gets the current size of the shared object, in bytes. |
|
|
static |
removeListener(objectName:String) |
Removes any listeners that were added using the addListener() method. |
Methods inherited from class Object