About synchronizing shared objects

Before attempting to work with a remote shared object, you should first check that the SharedObject.connect() method returned a value of true, indicating a successful connection, and then wait until you receive a result from the function you have assigned to the SharedObject.onSync handler. 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. The handler is also invoked the first time a client uses the SharedObject.getRemote() method to connect to a remote shared object that is persistent locally or on the server. In the latter case, all the object properties are set to empty strings, and SharedObject.onSync is invoked with the value of the code property 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 place some debug code in your SharedObject.onSync handler, as in the following example:

my_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
}

 

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

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