}
trace(so.data.now);
trace("SharedObject is " + so.size + " bytes");
so.flush();
When using the
flush()
careful to check whether the user has explicitly disabled local storage using the Flash Player
Settings Manager
(http://www.macromedia.com/support/documentation/en/flashplayer/
help/settings_manager07.html), as shown in the following example:
var so:SharedObject = SharedObject.getLocal("test");
trace("Current SharedObject size is " + so.size + " bytes.");
so.flush();
Values can be retrieved from a shared object by specifying the property's name in the shared
object's
property. For example, if you run the following code, Flash Player will display
data
how many minutes ago the SharedObject instance was created:
var so:SharedObject = SharedObject.getLocal("test");
if (so.size == 0)
{
// Shared object doesn't exist.
trace("created...");
so.data.now = new Date().time;
}
var ageMS:Number = new Date().time - so.data.now;
trace("SharedObject was created " + Number(ageMS / 1000 /
60).toPrecision(2) + " minutes ago");
trace("SharedObject is " + so.size + " bytes");
so.flush();
The first time the previous code is run, a new SharedObject instance named
created and have an initial size of 0 bytes. Because the initial size is 0 bytes, the
evaluates to
and a new property named
true
shared object's age is calculated by subtracting the value of the
time. Each subsequent time the previous code is run, the size of the shared object should be
greater than 0, and the code will trace how many minutes ago the shared object was created.
Displaying contents of a shared object
Values are stored in shared objects within the
within a shared object instance by using a
var so:SharedObject = SharedObject.getLocal("test");
so.data.hello = "world";
so.data.foo = "bar";
so.data.timezone = new Date().timezoneOffset;
for (var i:String in so.data)
392
Networking and Communication
method to write shared objects to a user's hard drive, you should be
now
data
for..in
is added to the local shared object. The
property from the current
now
property. You can loop over each value
loop, as the following example shows:
will be
test
statement
if
Need help?
Do you have a question about the FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 and is the answer not in the manual?
Questions and answers