Storing Local Data - Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual

Programming actionscript 3.0
Table of Contents

Advertisement

New shared object instances can be created using the static
SharedObject.getRemote()
persistent shared object that is available only to the current client, whereas the
method attempts to load a remote shared object that can be shared across multiple clients by
means of a server, such as Flash Media Server. If the local or remote shared object do not exist,
the
and
getLocal()
The following code attempts to load a local shared object named
doesn't exist, a new shared object with this name will be created.
var so:SharedObject = SharedObject.getLocal("test");
trace("SharedObject is " + so.size + " bytes");
If a shared object named test cannot be found, a new one is created with a size of 0 bytes. If
the shared object previously existed, its current size (in bytes) is returned.
You can store data in a shared object by assigning values to the data object, as seen in the
following example:
var so:SharedObject = SharedObject.getLocal("test");
so.data.now = new Date().time;
trace(so.data.now);
trace("SharedObject is " + so.size + " bytes");
If there is already a shared object with the name
value is overwritten. You can use the
object already exists, as the following example shows:
var so:SharedObject = SharedObject.getLocal("test");
if (so.size == 0)
{
// Shared object doesn't exist.
trace("created...");
so.data.now = new Date().time;
}
trace(so.data.now);
trace("SharedObject is " + so.size + " bytes");
The previous code uses the
specified name already exists. If you test the following code, you'll notice that each time you
run the code, the shared object is recreated. In order for a shared object to be saved to the
user's hard drive, you must explicitly call the
following example shows:
var so:SharedObject = SharedObject.getLocal("test");
if (so.size == 0)
{
// Shared object doesn't exist.
trace("created...");
so.data.now = new Date().time;
methods. The
methods will create a new SharedObject instance.
getRemote()
SharedObject.size
parameter to determine if the shared object instance with the
size
SharedObject.getLocal()
method attempts to load a locally
getLocal()
test
and the parameter
test
property to determine if a shared
SharedObject.flush()
or
getRemote()
. If this shared object
, the existing
now
method, as the

Storing local data

391

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents