Server-Side Communication ActionScript > SharedObject.lock

 

SharedObject.lock

Availability

Flash Communication Server MX.

Usage

SharedObject.lock()

Parameters

None.

Returns

An integer indicating the lock count: 0 or greater indicates success; -1 indicates failure. For proxied shared objects, always returns -1.

Description

Method; locks the shared object instance. This method gives the server-side script exclusive access to the shared object; when the SharedObject.unlock method is called, all changes are batched and one update message is sent to all the clients subscribed to this shared object. If you nest the SharedObject.lock and SharedObject.unlock methods, make sure there is an unlock for every lock; otherwise, clients are blocked from accessing the shared object.

You cannot use the SharedObject.lock method on proxied shared objects.

Example

This example locks the myShared shared object, executes the code that is to be inserted, and then unlocks the object:

var myShared = SharedObject.get("foo");
myShared.lock();
// insert code here that operates on the shared object
myShared.unlock();