About shared objects
Shared objects function like browser cookies. You use the SharedObject class to store data on the user's local hard disk and call that data during the same session or in a later session. Applications can access only their own SharedObject data, and only if they are running on the same domain. The data is not sent to the server and is not accessible by other Adobe® Flex® applications running on other domains, but can be made accessible by applications from the same domain.
Cookies and shared objects are very similar. Because most web programmers are familiar with how cookies work, it might be useful to compare cookies and local SharedObjects.
Cookies that adhere to the RFC 2109 standard generally have the following properties:
- They can expire, and often do at the end of a session by default.
- They can be disabled by the client on a site-specific basis.
- There is a limit of 300 cookies total, and 20 cookies maximum per site.
- They are usually limited to a size of 4 KB each.
- They are sometimes perceived to be a security threat, and as a result, they are sometimes disabled on the client.
- They are stored in a location specified by the client browser.
- They are transmitted from client to server through HTTP.
In contrast, shared objects have the following properties:
- They do not expire by default.
- By default, they are limited to a size of 100 KB each.
- They can store simple data types (such as String, Array, and Date).
- They are stored in a location specified by the application (within the user's home directory).
- They are never transmitted between the client and server.
Using the SharedObject class, you can create and delete shared objects, as well as detect the current size of a SharedObject object that you are using. The SharedObject class consists of the following methods.
Purges all of the data from the SharedObject object, and deletes the SharedObject file from the disk.
Immediately writes the SharedObject file to a file on the client.
Returns a reference to the client's domain-specific, local SharedObject object. If none exists, this method creates a new shared object on the client.
Gets the size of the SharedObject file, in bytes. The default size limit is 100 KB, although it can be larger if the client allows it.
In addition to these methods, SharedObject objects have the following properties:
Read-only property that represents the collection of attributes the shared object stores.
The shared object's event handler that is invoked for every warning, error, or informational note.
You use the SharedObject class to store small amounts of data on the client computer.