SharedObject Methods

The SharedObject architecture has a powerful series of methods. Its only property, data, allows you to set ActionScript variable types including objects and arrays as slots. There will be more on the definition of a slot later. The most powerful component of the SharedObject, however, is the onSync method. This method is responsible for handling data-change messages used to synchronize all clients connected to the Remote SharedObject. Here is a brief overview of the SharedObject ActionScript. The details of these ActionScript items are presented within the exercises of this chapter.


This method closes the connection between the Flash client and the server. If the SharedObject is persistent, when the client reconnects, it receives synchronization events from an information object sent from the server. If the SharedObject is not persistent, and this is the only (or last) client connected, the object is deleted.


This method is used in tandem with a local SharedObject, which is always persistent. When used, it transfers data stored in the local SharedObject to the file specified by the getLocal() method. This book doesn't review details about the local SharedObject.


This method returns the size of remote or local SharedObjects. It is important to monitor size when using local SharedObjects due to the ability for the client to set the maximum allowable disk space independent of your Flash movie.


This method instantiates the local SharedObject to an ActionScript variable. It takes two parameters (the name of the object and the file path) to store it on the host computer.


The following methods are only available with Flash Communication Server.


This method instantiates the remote SharedObject to a local variable. It must be used before the connect() method to declare the name of the SharedObject on the server, the application/instance details, and if it will be persistent or temporary.


This method associates the remote SharedObject with a pre-existing NetConnection. This method must be used before a remote SharedObject can be written to or accessed.


This method invokes a function handler defined in the SharedObject on each connected client. This process is known as broadcasting a message over the SharedObject. Functions that are defined in the remote SharedObject at the client or server can be called using send(). Popular uses might be triggering a sound effect or altering the client's movie somehow.


This is not frames per second; however, you can use it as a good analogy. This function declares the frequency of communication between the Flash player and the server, also known as updates per second. The higher this value, the faster the response by the client to the server. A value of (0) turns off any updates to the server and forces the user to invoke the update.

    Part I: 10 Quick Steps for Getting Started