最简单的计算在线人数的方法
通过 application.clients.length 就可以了
客户端需要的话可以call服务器端
定义的函数,最方便的还是使用共享对象来存取了,下面给出完整的实现方法。
在
服务器端的main.asc文件中写入:
- application.onAppStart = function() {
-
this.users_so = SharedObject.get('users_so');- };
-
application.onConnect = function(newClient, name)- {
-
// Accept the client's connection-
application.acceptConnection(newClient);-
i = application.clients.length;-
this.users_so.setProperty('users', i);- }
-
application.onDisconnect = function(client)- {
-
i = application.clients.length;-
this.users_so.setProperty('users', i);- }
在客户端fla文件中添加:
- users_so = SharedObject.getRemote('users_so', client_nc.uri, false);// 更新在线用户数users_so.onSync = function(list) {txtNumberUsers.text = users_so.data.users;
- }