User Guide

SharedObject class 117
Sharing data in real time
A shared object can share data among multiple clients in real time. For example, you can
open a remote shared object that stores real-time data that is visible to all clients connected
to the object, such as a list of users connected to a chat room. When a user enters or leaves
the chat room, the object is updated and all clients that are connected to the object see the
revised list of chat room users.
It is important to understand the following information about using shared objects in server-
side ActionScript:
The server-side ActionScript method SharedObject.get() creates remote shared objects
(RSOs); there is no server-side method that creates local shared objects (LSOs).
The RSO file extension is .fso; RSOs are stored on the server in a subdirectory of the
application that created them.
Server-side shared objects can be non-persistent (exist for the duration of an application
instance) or persistent (stored on the server after an application closes).
To create a persistent shared object, set the
persistence parameter of the
SharedObject.get() method to true. Persistent shared objects let you maintain an
applications state.
Every RSO is identified by a unique name and contains a list of name-value pairs, called
properties, like any other ActionScript object. A name must be a unique string and a value
can be any ActionScript data type.
To get the value of a server-side shared object property, call
SharedObject.getProperty(). To set the value of a server-side shared object property,
call
SharedObject.setProperty().
To clear a shared object, call the SharedObject.clear()method; to delete multiple
shared objects, call the
Application.clearSharedObjects() method.
Server-side shared objects can be owned by the current application instance or by another
application instance. The other application instance can be on the same server or on a
different server. References to shared objects that are owned by a different application
instance are called proxied shared objects.
If you write a server-side script that modifies multiple properties, you can prevent other
clients from modifying the object during the update by calling the
SharedObject.lock()
method before updating the object. Then you can call
SharedObject.unlock() to commit
the changes and allow other changes to be made. Call
SharedObject.mark() to deliver
change events in groups within the lock() and unlock() methods.
NOTE
Unlike client-side shared objects, server-side shared objects do not have a data
property.