SharedObject.getLocal()
743
Although the
localPath
parameter is optional, developers should give some thought to its use,
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
localPath
set to the default value of the full path to the SWF file, then no
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
localpath
parameter. The most permissive option is to set the
localPath
parameter to "/",
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
localPath
parameter with folder names that are
contained in the full path to the SWF file. For example, your
localPath
parameter options for
the
portfolio
shared object created by the SWF file at www.myCompany.com/apps/
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
myText_ta
. Copy the following code into the main Timeline (click on 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 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
kookie
:
// Get the kookie
var my_so:SharedObject = SharedObject.getLocal("kookie");
Summary of Contents for FLASH MX 2004-ACTIONSCRIPT LANGUAGE
Page 1: ...ActionScript Language Reference...
Page 20: ...20 Contents...
Page 24: ...24 Chapter 1 Introduction...
Page 145: ...Button onKeyDown 145 See also Button onKeyUp...
Page 186: ...186 Chapter 2 ActionScript Language Reference See also Camera onActivity Camera setMotionLevel...
Page 202: ...202 Chapter 2 ActionScript Language Reference See also break default strict equality switch...
Page 282: ...282 Chapter 2 ActionScript Language Reference See also break continue while...
Page 383: ...LoadVars addRequestHeader 383 See also XML addRequestHeader...
Page 388: ...388 Chapter 2 my_lv load place a valid URL pointing to a text file here...
Page 463: ...Microphone setRate 463 See also Microphone rate...
Page 469: ...Microphone silenceLevel 469 See also Microphone gain Microphone setSilenceLevel...
Page 480: ...480 Chapter 2 ActionScript Language Reference See also Mouse addListener...
Page 529: ...MovieClip globalToLocal 529 See also MovieClip getBounds MovieClip localToGlobal...
Page 612: ...612 Chapter 2 ActionScript Language Reference See also MovieClipLoader onLoadStart...
Page 623: ...NetConnection class 623 See also NetStream class Video attachVideo...
Page 649: ...Number 649 See also NaN Number class...
Page 679: ...on 679 on release trace X this _x trace Y this _y stopDrag See also onClipEvent...
Page 683: ...onUpdate 683 buttonLabel textColor my_mc labelColor...
Page 788: ...788 Chapter 2 ActionScript Language Reference See also private public...
Page 1001: ...Video height 1001 my_mc _height my_mc my_video height See also MovieClip _height Video width...
Page 1022: ...1022 Chapter 2 ActionScript Language Reference See also XML createElement...
Page 1057: ...XML xmlDecl 1057 See also XML docTypeDecl XML toString...
Page 1070: ...1070 Chapter 2 ActionScript Language Reference...