远程共享对象 Fms Flex 4 的问题

发布于 2024-11-01 20:51:37 字数 511 浏览 1 评论 0原文

我正在尝试开发一个应用程序,同时用户可以在其中进行交互,并且我需要一个持久的远程共享对象,其中包含当前会话中的用户列表。 当新用户进入会话时,他会获得带有列表的服务器对象。该列表应该包含会话中的所有其他用户,但未定义。

我首先这样做:

users_so = SharedObject.getRemote("users_so", nc.uri, true);
users_so.connect( nc );
users_so.addEventListener( SyncEvent.SYNC, usersSyncHandler );

然后将属性设置为共享对象

remoteUsers = new ArrayCollection();
    remoteUsers.addItem(displayName);
    users_so.setProperty("usersID", remoteUsers);

,最后将用户放入列表中。

谢谢!

I'm trying to develop an application where simultaneous users can interact and i need to have a persistent remote shared object with the list of users currently in session.
When a new user enter in the session he get the server's object with the list. That list was supose to have all the others users in session but is undefined.

I'm doing this first:

users_so = SharedObject.getRemote("users_so", nc.uri, true);
users_so.connect( nc );
users_so.addEventListener( SyncEvent.SYNC, usersSyncHandler );

then i set property to shared object

remoteUsers = new ArrayCollection();
    remoteUsers.addItem(displayName);
    users_so.setProperty("usersID", remoteUsers);

and finaly i put users in the list.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小矜持 2024-11-08 20:51:37

我想说,您需要使用 sharedObject.setDirty("usersID");

SharedObject 无法知道您更改了 ArrayCollection 的内容,因为对它的引用没有更改。您可以使用 setDirty() 强制同步。

注意: SharedObject.setProperty()
方法实现 setDirty()
方法。大多数情况下,比如当
属性的值是一个原始值
键入字符串或数字,您会
使用 setProperty() 而不是 setDirty。
然而,当财产的价值
是一个包含它自己的对象
属性,使用setDirty()来表示
当对象内的值具有
改变了。总的来说,这是一个好主意
调用 setProperty() 而不是
setDirty(),因为 setProperty()
仅在以下情况下更新属性值
该值已经改变,而
setDirty() 强制同步
所有订阅的客户。

我为此使用简单的动态对象。客户端有只读的 SharedObject,服务器决定何时从该 SharedObject 添加/删除客户端。

m_soSharedObject(远程),m_userListObject(本地)

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);
}

I would say, that you need to use sharedObject.setDirty("usersID");

SharedObject can't know, that you changed content of ArrayCollection, because the reference to it didn't change. You can use setDirty() to force synch.

Note: The SharedObject.setProperty()
method implements the setDirty()
method. In most cases, such as when
the value of a property is a primitive
type like String or Number, you would
use setProperty() instead of setDirty.
However, when the value of a property
is an object that contains its own
properties, use setDirty() to indicate
when a value within the object has
changed. In general, it is a good idea
to call setProperty() rather than
setDirty(), because setProperty()
updates a property value only when
that value has changed, whereas
setDirty() forces synchronization on
all subscribed clients.

I am using simple dynamic object for this. Client has read-only SharedObject and server decides when to add/remove client from this SharedObject.

m_so is SharedObject (remote), m_userList is Object (local)

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);
}
野侃 2024-11-08 20:51:37

我找到了一种更适合我的解决方案:

它包括调用服务器上的远程函数,然后广播到所有客户端。然后,客户应用必要的更改,使解决方案更加稳定。

I found one solution that works better for me:

It consists in calling remote funcions on server and then broadcast to all clients. The clientes then apply the necessery changes making the solution a lot more stable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文