The script template in Listing E.8 can be used to handle any SharedObject onSync event on the client and the server.
onSyncTemplate = function (info) {
trace("Synchronizing Data");
//
// Use this structure as a prototype for your onSync Handlers.
// Loop through the Array of Objects using the IN operator
//
for (name in info) {
trace("[sync] Reading Array Object #"+name+" code("+info[name].code+",
"+info[name].name+")");
//
// ::: The following switch handles code values returned by the object
// Place Code Here
//
switch (info[name].code) {
case "change" :
trace("::Handle a change of data by another client");
// Place Code Here
break;
case "success" :
trace("::Handle successful change of data from this server");
// Place Code Here
break;
case "reject" :
trace("::Handle a rejected SharedObject write operation");
// Place Code Here
break;
case "clear" :
trace("::Handle an initialization of the SharedObject");
// Place Code Here
break;
case "delete" :
trace("::Handle deleted Attributes");
// Place Code Here
}
// ::: End the Switch, continue Looping through the Information Object
}
// ::: Complete the onSync Handler
};
// Connect to Remote SharedObject using the onSync Template
rem_so = SharedObject.getRemote("myRemoteSO", nc.uri, true);
rem_so.onSync = onSyncTemplate;
rem_so.connect(nc);