Using SharedObjects

Shared objects are basically cookies that get stored on a users machine by the browser.  Here's a little code sample to demonstrate; in this case the SharedObject was used to remember the user's login name so that they wouldn't have to type it every time they logged in.

 

To create and set values in a SharedObject (note that we use the 'data' property of the SharedObject to store our info)...

//create a shared object to store the user name this line actually
//specifies the file name (userFile), it will have an extension of .sol ...
var so:SharedObject = SharedObject.getLocal("userFile");
//create and populate a userLoginName property for the shared object...
so.data.userLoginName = txtUserLoginName.text;
//write the file to the users disk...
so.flush();



To retrieve the SharedObject, if it exists...

var so:SharedObject = SharedObject.getLocal("userFile");
if(so.data.userLoginName != undefined){
    this.txtUserLoginName.text = so.data.userLoginName;
    this.txtPassword.setFocus();
}

 

To delete the SharedObject...

 

so.clear();

so.flush();


RECENT ARTICLES