Flash Media Server |
|||
| Client-Side ActionScript Language Reference for Flash Media Server 2 > Client-Side ActionScript Language Reference > SharedObject class > SharedObject.onSync | |||
myRemote_so.onSync = function(objArray){ // your code here }
objArray An array of objects; each object contains properties that describe the changed members of a remote shared object.
Nothing.
Event handler; initially invoked when the client and server shared object are synchronized after a successful call to SharedObject.connect(), and later invoked whenever any client changes the attributes of the data property of the remote shared object. You must create a function to override this handler and process the information object sent by this event handler. The properties of each object are code, name, and oldValue.
When you initially connect to a remote shared object that is persistent locally and/or on the server, all the properties of this object are set to empty strings. Otherwise, Flash sets code to "clear", "success", "reject", "change", or "delete".
"clear" means either that you have successfully connected to a remote shared object that is not persistent on the server or the client, or that all the properties of the object have been deleted--for example, when the client and server copies of the object are so far out of sync that Flash resynchronizes the client object with the server object. In the latter case, SharedObject.onSync is invoked again, this time with the value of code set to "change"."success" means the client changed the shared object. "reject" means the client tried unsuccessfully to change the object; instead, another client changed the object. "change" means another client changed the object or the server resynchronized the object. "delete" means the attribute was deleted. The name property contains the name of the property that has been changed.
The oldValue property contains the former value of the changed property. This parameter is null unless code has a value of "reject" or "change".
To minimize network traffic, this method is not called when a client "changes" a property to the same value it currently has. That is, if a property is set to the same value multiple times in a row, this method is invoked the first time the property is set, but not during subsequent settings, as shown in the following example:
my_so.data.x = 15; // The following line invokes onSync. my_so.data.x = 20; /* The following line doesn't invoke onSync, even if issued by a different client. */ my_so.data.x = 20;
The following examples creates or gets a remote shared object named position:
var myRemote_so:SharedObject = SharedObject.getRemote("position", my_nc.uri, false);
The following updates the ball position when another participant moves the ball; sharedBall_mc is a movie clip on the Stage:
myRemote_so.onSync = function(list) {
sharedBall_mc._x= myRemote_so.data.x;
sharedBall_mc._y= myRemote_so.data.y;
}
/* You must always call connect() in order to successfully
connect to the shared object and share data. */
myRemote_so.connect(my_nc);
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/fms/2/docs/00000610.html