17.6. Broadcasting Data to Remote Shared Object Clients
Problem
You want to send data to all the clients of a FlashCom application that are connected to a remote shared object.
Solution
Use the SharedObject.onSync( )
method
to catch synchronization events, and use the
SharedObject.send( )
method to broadcast
messages without writing to the RSO.
Discussion
Every time the server-side data for a remote shared object changes,
FlashCom attempts to synchronize the client-side data for all clients
connected to that RSO. The SharedObject.onSync(
)
method for a client-side remote shared object is
automatically invoked whenever a synchronization attempt has
occurred, so you can monitor all synchronization events. (See more on
this in Recipe 16.8.) This is useful in
situations in which a relatively small amount of data is shared among
multiple clients. Whenever one client makes a change, all the other
clients are automatically notified. The onSync(
)
method works the same regardless of whether the remote
shared object is persistent.
You can also manually invoke a client-side method on all clients
connected to a remote shared object by using the
SharedObject.send( )
method, and you can call
the send( )
method from either a server-side or
client-side remote shared object. In either case, the send(
)
method requires that you specify the name of the method to invoke on the client(s). You should then ensure that the client movies have a method with that same name defined for the client-side remote ...
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.