SharedObject
1081
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.
Macromedia 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.
NO
TE
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.
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...