126
Client-Side ActionScript Language Reference
Description
Method; returns a reference to a locally persistent shared object that is available only to the
current client. To create a shared object that is available to multiple clients by means of the
Flash Media Server, use
SharedObject.getRemote()
.
Because local shared objects are available only to a single client, the
SharedObject.onSync
handler is not called when the object is changed, and there is no need to implement conflict-
resolution techniques.
To avoid name collisions, Flash looks at the location of the SWF file that is creating the shared
object. For example, if a SWF file at www.myCompany.com/apps/stockwatcher.swf creates a
shared object named
portfolio
, that shared object will not conflict with another object
named
portfolio
that was created by a SWF file at www.yourCompany.com/
photoshoot.swf, because the SWF files originate from two different directories.
Example
The following example creates a shared object that stores text that is typed into a TextInput
component instance. The resulting SWF file loads the saved text from the shared object when
it starts playing. Every time the user presses Enter, the text in the text field is written to the
shared object.
To use this example, drag a TextInput component onto the Stage, and name the instance
myText_ti
. Copy the following code into the main Timeline (click in an empty area of the
Stage or press Escape to remove focus from the component):
// Create the shared object and set localpath to server root.
var my_so:SharedObject = SharedObject.getLocal("savedText", "/");
/* Load saved text from the shared object into the myText_ti TextInput
component. */
myText_ti.text = my_so.data.myTextSaved;
/* Assign an empty string to myText_ti if the shared object is undefined
to prevent the text input box from displaying "undefined" when
this script is first run. */
if (myText_ti.text == undefined) {
myText_ti.text = "";
}
// Create a listener object and function for <enter> event.
var textListener:Object = new Object();
textListener.enter = function(eventObj:Object) {
my_so.data.myTextSaved = eventObj.target.text;
my_so.flush();
};
NO
T
E
If the user has chosen to never allow local storage for this domain, the object will not be
saved locally, even if a value for
localPath
is specified. For more information, see
“Local
disk space considerations” on page 115
.