1

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

Jack X.
  • 85
  • 2
  • 10
  • Did you use `so.flush()`? – Vesper Jul 21 '16 at 14:17
  • I didn't know that. 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? Thanks. – Jack X. Jul 21 '16 at 14:53
  • @Vesper, BTW, I created the SO using getRemote, instead of getLoal, do I still need to call so.flush()? I read through the documentation and it was not super clear to me if the flush() call was for both getLocal() and getRemote() SOs. – Jack X. Jul 21 '16 at 15:12

1 Answers1

2

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

Community
  • 1
  • 1
null
  • 5,207
  • 1
  • 19
  • 35
  • Is this still true if I created the SO using getRemote()? I called flush() and got "Error: Error #2130: Unable to flush SharedObject." – Jack X. Jul 21 '16 at 15:19
  • @JackX. I edited my answer to include another suggestion. – null Jul 21 '16 at 15:33
  • The setProperty() approach worked! I spent a couple of hours on this and you saved me. Thanks man! – Jack X. Jul 21 '16 at 16:09