Creating a local SharedObject
Table of Contents
To create a local SharedObject, use the getLocal() method, which has the following syntax:
SharedObject.getLocal("objectName"): SharedObject
For example:
var myLSO:SharedObject;
myLSO = SharedObject.getLocal("foo");
When you create a SharedObject, Macromedia Flash Player creates a new directory for the application and domain, and creates an empty *.sol file that stores the SharedObject data. The default location of this file is in a subdirectory of the user's home directory; for example: c:/Documents and Settings/username.user_domain/Application Data/Macromedia/Flash Player/web_domain/lso.mxml.swf/. While usually predictable, the location of the StoredObject file can be anywhere that Flash Player has access to within its sandbox and can have any name that Flash Player assigns to it.
By default, Flash can save locally persistent SharedObjects of up to 100K in size. When you try to save a larger set of data, Flash Player displays the Local Storage dialog box, which lets the user allow or deny local storage for the domain that is requesting access.
You can create multiple SharedObjects for the same Flex application. To do this, you assign each of them a different name:
myLSO = SharedObject.getLocal("bar");
myLSO2 = SharedObject.getLocal("baz");
This creates a bar.sol file and a baz.sol file in the Flex application's directory.
You add data to a SharedObject using the data property of the SharedObject object. To write a new value to the SharedObject, use the following syntax:
sharedObject_ID.data.variable = value;
For example:
currentUserName = "Omarosa"; itemsArray = new Array(101,346,483); currentUserIsAdmin = true; myLSO.data.userName = currentUserName; myLSO.data.itemNumbers = itemsArray; myLSO.data.adminPrivileges = currentUserIsAdmin;
You can store simple data types in a SharedObject. These types are Number, String, Boolean, XML, Date, Array, and Object. You cannot store built-in ActionScript types such as Function or MovieClip in a SharedObject.
After you assign values to the data property, you must instruct Flash Player to write those values to the SharedObject's file. To force Flash Player to write the values to the SharedObject's file, use the flush() method:
myLSO.flush();
If you do not call the flush() method, Flash Player writes the values to the file when the application quits. However, this does not provide the user with an opportunity to increase the available space that Flash Player has to store the data if that data exceeds the default settings. It is therefore a good practice to call the flush() method.

