Flash Lite 2.x and 3.0 ActionScript Language Reference

getLocal (SharedObject.getLocal method)

public static getLocal(name:String) : SharedObject

Returns a reference to a locally persistent shared object that is available only to the current client. If the shared object does not already exist, getLocal() creates one. This method is a static method of the SharedObject class.

Note: In Flash Lite, a shared object cannot be shared between two SWF files.

To assign the object to a variable, use syntax like the following

var so:SharedObject = SharedObject.getLocal("savedData")

Because the data may not be immediately available for reading on the device, the application must create and register a listener for the shared object identified by name. For details, see the description of the addListener() method.

Parameters

name:String - A string that represents the name of the object. The name can include forward slashes (/); for example, work/addresses is a valid name. Spaces are not allowed in a shared object name, nor are the following characters:

 ~ % & \ ; : " ' , < > ? # 


Returns

SharedObject - A reference to a shared object that is persistent locally and is available only to the current client. If Flash can't create or find the shared object, getLocal() returns null.

This method fails and returns null if persistent shared object creation and storage by third-party Flash content is prohibited by the device.

Example

The following example saves the last frame that a user entered to a local shared object named kookie:

// Get the kookie
var my_so:SharedObject = SharedObject.getLocal("kookie");

// Get the user of the kookie and go to the frame number saved for this user.
if (my_so.data.user != undefined) {
    this.user = my_so.data.user;
    this.gotoAndStop(my_so.data.frame);
}

The following code block is placed on each SWF file frame:

// On each frame, call the rememberme function to save the frame number.
function rememberme() {
    my_so.data.frame=this._currentframe;
    my_so.data.user="John";
}