Search code examples
actionscript-3flashflash-cs5flashdevelopshared-objects

SharedObject: can receive event from other clients but never fires event after saving data


I'm using a SharedObject to create a simple chat app. The SharedObject was created fine and my app could receive the sync event when other clients updates the data on the SO. However, the problem comes when my app tries to saves the data on the SO to signal other clients. I've verified that the data was changed using the following code:

trace("before:"+so.data.chatMessage);
so.data.chatMessage = msg.text;
trace("after:"+so.data.chatMessage);

It said "before:abc" and "after:def". Unfortunately no clients received the sync event after the data on the SO changed including the client that made the data change itself. So this means this client can receive other client's message but itself message never gets out.

Anybody has seen such issue before? Thanks, Jack


Solution

  • You have to call flush():

    If you don't use this method, Flash Player writes the shared object to a file when the shared object session ends — that is, when the SWF file is closed, when the shared object is garbage-collected because it no longer has any references to it, or when you call SharedObject.clear() or SharedObject.close().

    or

    use setProperty() to change the property:

    Updates the value of a property in a shared object and indicates to the server that the value of the property has changed.

    As you only change a property of the data object, there's no notification going on that this value has changed.

    Calling so.flush() resulted in "Error: Error #2130: Unable to flush SharedObject." It did not print an internal error, though. So it seems the problem was the flush couldn't be successful... Any idea how could happen?

    Take a look at this other question:

    Error #2130 Unable to flush sharedObject