Using Persistent Store via SharedObje ct
Shared Objects are used to store limited amounts of data on the device. It is smiliar to a browser cookie with two exceptions that it can store more complex data than simple text, and they do not expire by default.
Shared Objects have three important methods:
- getLocal()
haredObject - Used to create a locally persistant shared object or returns a reference if hasn't been previously created. - flush()
tring - Immediately writes a locally persistent object to a local file. - clear():void - Destroys a shared object.
By default, <appname>.sol file which contains your SharedObject is stored within the application directory's data folder "<appname>/data/#SharedObjects/<appname>.swf/" when the flush() function is called.
Due to the BlackBerry® Tablet OS security model, an application can only play within its own sandbox and hence it's SharedObjects can't be accessed by other applications.
The following snippets of code illustrate the use of the SharedObjects:
// Creates the SharedObject variable. The SharedObject is created in
// its default location <appname>/data/#SharedObjects/<appname>.swf/
public var sharedObj:flash.net.SharedObject;
sharedObj = flash.net.SharedObject.getLocal("myJournal");
// Adding an Array List to the Object and saving the data
sharedObj.data.array = sObjArray;
sharedObj.flush();
// Deleting the content of the SharedObject.
sharedObj.clear();
Using an alternate url for your SharedObject:
// Creates the SharedObject variable. The SharedObject is created in
// the set location <appname>/data/#SharedObjects/
public var sharedObj:flash.net.SharedObject;
sharedObj = flash.net.SharedObject.getLocal("myJournal", "/");
See the following learning resources for more information on the API used in this article:
SharedObject API
A journal sample application is attached demonstrating the use of SharedObjects.

