Using Communication Objects > SharedObject object > SharedObject.onSync

 

SharedObject.onSync

Before attempting to work with a remote shared object, you should first check that SharedObject.connect returned true, indicating a successful connection, and then wait until you receive a result from the function you have assigned to SharedObject.onSync. If you fail to do so, any changes you make to the object locally—before SharedObject.onSync is invoked—may be lost.

The SharedObject.onSync handler is invoked when any of the SharedObject.data properties of the remote shared object are changed, and also the first time a client uses the SharedObject.getRemote command to connect to a remote shared object that is persistent locally and/or on the server. In the latter case, all the properties of the object are set to empty strings, and SharedObject.onSync in invoked with the value of code set to "clear". Then SharedObject.onSync is invoked again, this time with the value of code set to "change", and the properties of the client's instance of the remote shared object will be set to match those on the server.

If you are having problems understanding how your shared object is behaving, it helps to put some debug code in your SharedObject.onSync handler:

so.onSync = function(list) {
	for (var k in list) {
		trace("name = " + list[k].name + ", event = " + list[k].code);
	}
	// do whatever else you want to do here
}