Server-Side Communication ActionScript > SharedObject.onSync

 

SharedObject.onSync

Availability

Flash Communication Server MX.

Usage

SharedObject.onSync = function(list){
	return;
};

Parameters

list An array of objects that contain information about the properties of a shared object that have changed since the last time the onSync method was called. The notifications for proxied shared objects are different than for shared objects that are owned by the local application instance. The following tables list the descriptions for each type of shared object.

 
Local shared objects

Code

Meaning

change

A property was changed by a subscriber.

delete

A property was deleted by a subscriber.

name

The name of a property that has changed or been deleted.

oldValue

The old value of a property. This is true for both change and delete messages; on the client, oldValue is not set for delete.


Note: Changing or deleting a property on the server side using the SharedObject.setProperty method always succeeds, so there is no notification of these changes.

 
Proxied shared objects

Code

Meaning

success

A server change of the shared object was accepted.

reject

A server change of the shared object was rejected. The value on the remote instance was not changed.

change

A property was changed by another subscriber.

delete

A property was deleted. This notification can occur when a server deletes a shared object or if another subscriber deletes a property.

clear

All the properties of a shared object are deleted. This can happen when the server's shared object is out of sync with the master shared object or when the persistent shared object migrates from one instance to the other. This event is typically followed by a change message to restore all the server's shared object properties.

name

The name of a property that has changed or been deleted.

oldValue

The old value of the property. This is only valid for the reject, change and delete codes.


Note: The SharedObject.onSync method is called when a shared object has been successfully synchronized with the server. The list object may be empty if there is no change in the shared object.

Returns

Nothing.

Description

Event handler; invoked when a shared object changes. You should set this method to point to a function you define in order to receive notification of changes made by other subscribers for shared objects owned by the local application instance. You should also set this method to get the status of changes made by the server as well as by other subscribers for proxied shared objects.

Example

The following example creates a function that is invoked whenever a property of the shared object so changes:

// create a new NetConnection object
nc = new NetConnection();
nc.connect("rtmp://server1.xyx.com/myApp");
// create the shared object 
so = SharedObject.get("MasterUserList", true, nc);
// the list parameter is an array of objects containing information
// about successfully of unsuccessfully changed properties
// from the last time onSync() was called
so.onSync = function(list) {
	for (var i = 0; i < list.length; i++) {
		switch (list[i].code ) {
			case "success":
				trace ("success");
				break;
			case "change":
				trace ("change");
				break;
			case "reject":
				trace ("reject");
				break;
			case "delete":
				trace ("delete");
				break;
			case "clear":
				trace ("clear");
				break;
		}
	}
};