2016-07-21 34 views
1

我正在使用SharedObject创建一个简单的聊天应用程序。 SharedObject创建的很好,当其他客户端更新SO上的数据时,我的应用程序可以接收同步事件。但是,当我的应用程序尝试保存SO上的数据以向其他客户端发送信号时,问题就来了。我已经验证了数据使用下面的代码更改:SharedObject:可以接收来自其他客户端的事件,但从未在保存数据后触发事件

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

它说:“之前:ABC”和“之后:DEF”。不幸的是,在SO上的数据发生变化(包括使数据自行更改的客户端)后,没有客户端收到同步事件。所以这意味着这个客户端可以接收到其他客户端的消息,但是它本身的消息永远不会出现

以前有人见过这样的问题吗?谢谢, 杰克

+0

你使用'so.flush()'? – Vesper

+0

我不知道。调用so.flush导致“错误:错误#2130:无法刷新SharedObject”。不过,它没有打印内部错误。所以看起来问题是冲洗不能成功......任何想法如何发生?谢谢。 –

+0

@Vesper,顺便说一句,我创建了使用getRemote而不是getLoal的SO,我还需要调用so.flush()吗?我仔细阅读了文档,如果flush()调用同时适用于getLocal()和getRemote()SO,那么对我来说并不是非常清楚。 –

回答

2

你必须调用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() .

使用setProperty()更改的属性:

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

当你只改变data对象的属性,没有通知会发生这个值已经改变。

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?

在此的其他问题请看:

Error #2130 Unable to flush sharedObject

+0

如果我使用getRemote()创建SO,这仍然是真的吗?我调用flush()并得到“错误:错误#2130:无法刷新SharedObject。” –

+0

@JackX。我编辑了我的答案,以包含另一个建议。 – null

+0

setProperty()方法奏效!我花了几个小时在这个,你救了我。谢啦! –

相关问题