开发者

Problems with remote shared objects Fms Flex 4

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 开发者_如何学Pythonenter 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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜