在客户端对so进行大量更新时,容易出现so不同步的情况
个人总结原因如下。 1.网络延时问题 2.SharedObject实现机制问题
原本一直以为,Remote SharedObject 是事件驱动的,当SO发生改变量,就会把改变的内容传到服务器,但查了一个帮助文档,发现SO并不是事件驱动的,而是每隔一个时间,update一次更新。
帮助文档中的相关内容
SharedObject.setFps() Availability ■Flash Player 6. ■Flash Communication Server MX 1.0. Usage myRemote_so.setFps(updatesPerSecond) Parameters updatesPerSecond A number that specifies how often a client’s changes to a remote shared object are sent to the server. The default value is the frame rate of the SWF file. ■To send changes immediately and then stop sending changes, pass 0 for updatesPerSecond. ■To reset updatesPerSecond to its default value, pass a value less than 0. Returns A Boolean value of true if the update was accepted; otherwise, false. Description Method; specifies the number of times per second that a client’s changes to a shared object are sent to the server. Use this method when you want to control the amount of traffic between the client and the server. For example, if the connection between the client and server is relatively slow, you may want to set updatesPerSecond to a relatively low value. Conversely, if the client is connected to a multiuser game in which timing is important, you may want to set updatesPerSecond to a relatively high value. If you want to manually control when updates are sent, issue this command with updatesPerSecond set to 0 when you want to send changes to the server. For example, if you want to let the user push a button that sends updates to the server, attach myRemoteSharedObject.setFps(0) to the button. Regardless of the value you pass for updatesPerSecond, changes are not sent to the server until SharedObject.onSync has returned a value for the previous update. That is, if the response time from the server is slow, updates may be sent to the server less frequently than the value specified in updatesPerSecond. |
因此,在做大量数据更新时,可能导致不同步的出现。
解决方法有两种, 1 是把大量的要更新的数据放在一个临时的变量中,然后再一次性赋予SO. 2 使用setFps(0) setFps(-1) 来控制SO 的update ,让所有应该一次更新的数据就位后,再更新server 的 SO
|