Understanding shared object flow

Shared objects simplify the developer's task in sharing data between multiple users. A Flash client application subscribes to a remote shared object by issuing a SharedObject.getRemote() command, which returns a reference to the remote shared object. The client then issues a SharedObject.connect() command to connect the remote shared object to the server. Calling SharedObject.connect() associates the SharedObject with the NetConnection object (which is the connection used for sending and receiving data to and from the server), so the shared object can send and receive updates to and from the server.

After the client is connected to the shared object, the server sends out a synchronization message for the shared object, which is handled by the SharedObject.onSync event handler defined on the client. When the client, the server, or any other movie instance makes a change to the shared object, the server again sends out a synchronization message for the shared object.

Each synchronization message contains a code that specifies the nature of the change that occurred to the shared object. The code changes depending on the circumstances. For example, when a client first connects to a shared object, the code that accompanies the synchronization message has a value of clear; a value of success indicates that the client successfully modified the contents of the shared object. For a complete list of codes and their descriptions, see the SharedObject.onSync entry in the Client-Side ActionScript Language Reference for Flash Media Server 2.

The following diagram illustrates a scenario in which two clients, Client 1 and Client 2, connect to the same remote shared object, obj1. When each client first connects to the shared object, a clear synchronization message is returned by the server. Client 1 then modifies a data property of obj1, called x, setting it equal to 4. Client 1 receives a success synchronization message, indicating that the change to the shared object was successful; Client 2 receives a change synchronization message, indicating that the obj1 shared object is modified.



Shared object flow.



 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fms/2/docs/00000043.html