MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference page 743

Actionscript language reference
Table of Contents

Advertisement

Although the
localPath
especially if other SWF files will need to access the shared object. If the data in the shared object
are specific to one SWF file that will not be moved to another location, then use of the default
value makes sense. If other SWF files need access to the shared object or if the SWF file that
creates the shared object will later be moved, then the value of this parameter can have a profound
effect on whether any SWF files will be able to access the shared object. For example, if you create
a shared object with
other SWF file will be able to access that shared object. If you later move the original SWF file to
another location, then not even that SWF file will be able to access the data already stored in the
shared object.
You can reduce the likelihood that you will inadvertently restrict access to a shared object by using
the
parameter. The most permissive option is to set the
localpath
which makes the shared object available to all SWF files in the domain, but will increase the
likelihood of name collisions with other shared objects in the domain. More restrictive options are
available to the extent that you can append the
contained in the full path to the SWF file. For example, your
the
shared object created by the SWF file at www.myCompany.com/apps/
portfolio
stockwatcher.swf are: "/"; "/apps"; or "/apps/stockwatcher.swf". You will need to determine which
option provides enough flexibility for your application.
Example
The following example creates a shared object that stores text typed into a TextInput component
instance. The resulting SWF file will load 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
. Copy the following code into the main Timeline (click on an empty area of the Stage
myText_ta
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 shared object into 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 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();
};
// register listener with TextInput component instance
myText_ti.addEventListener("enter", textListener);
The following example saves the last frame a user entered to a local shared object
// Get the kookie
var my_so:SharedObject = SharedObject.getLocal("kookie");
parameter is optional, developers should give some thought to its use,
set to the default value of the full path to the SWF file, then no
localPath
localPath
parameter with folder names that are
localPath
localPath
SharedObject.getLocal()
parameter to "/",
parameter options for
:
kookie
743

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flash mx

Table of Contents