我会说,你需要使用sharedObject.setDirty("usersID");
SharedObject 无法知道您更改了 ArrayCollection 的内容,因为对它的引用没有更改。您可以使用 setDirty() 强制同步。
注意: SharedObject.setProperty() 方法实现了 setDirty() 方法。在大多数情况下,例如当属性的值是基本类型(如 String 或 Number)时,您将使用 setProperty() 而不是 setDirty。但是,当属性的值是包含其自身属性的对象时,请使用 setDirty() 来指示对象中的值何时发生更改。通常,调用 setProperty() 而不是 setDirty() 是个好主意,因为 setProperty() 仅在属性值发生更改时更新该值,而 setDirty() 会强制所有订阅的客户端同步。
我为此使用简单的动态对象。客户端具有只读的 SharedObject,服务器决定何时从该 SharedObject 中添加/删除客户端。
m_so
是SharedObject
(远程),m_userList
是Object
(本地)
if(m_so.data.userList != null) {
for (var key:String in m_so.data.userList) {
if(m_userList[key] == null) {
_addUser(m_so.data.userList[key]);
}
}
for(var clientId:String in m_userList) {
if(m_so.data.userList[clientId] == null) {
_removeUser(clientId);
}
}
}
application.onAppStart = function () {
userList = {};
so = SharedObject.get("roster", false);
so.setProperty("userList", userList);
}
application.onConnect = function (client /*Client*/, userId /*string*/) {
application.acceptConnection(client);
client.userId = userId;
userList[userId] = userId;
so.setProperty("userList", userList);
}
application.onDisconnect = function (client /*Client*/) {
var userId = client.userId;
delete userList[userId];
so.setProperty("userList", userList);
}