学了这么多,智商跟我差不多的,概念应该都搞混了
学了就要用。练练吧,做个在线列表,这次没有用ShareObject而是把用户名都装到一个application.onlineList数组里
通过遍历application.clients来广播给各个client,上线下线就是对onlinelist数组的处理。看看吧
点此下载
Client:
server端
![[sweat]](http://www.nshen.net/blog/styles/default/images/smilies/icon_sweat.gif)
学了就要用。练练吧,做个在线列表,这次没有用ShareObject而是把用户名都装到一个application.onlineList数组里
通过遍历application.clients来广播给各个client,上线下线就是对onlinelist数组的处理。看看吧
![](http://www.nshen.net/blog/styles/default/images/icon_file.gif)
Client:
btn.onRelease = function() {
if (_root.id.text != "") {
_root.init();
}
};
function init() {
IDNUM = _root.id.text;
//这个为登陆名
//IDPASS = "456";
mync = new NetConnection();
mync.onStatus = function(info) {
trace(info.code);
};
mync.connect("rtmp://localhost/phone", IDNUM, IDPASS);
mync.onlineList = function(list) {
//填充List组件
mylist.labels = list;
};
}
if (_root.id.text != "") {
_root.init();
}
};
function init() {
IDNUM = _root.id.text;
//这个为登陆名
//IDPASS = "456";
mync = new NetConnection();
mync.onStatus = function(info) {
trace(info.code);
};
mync.connect("rtmp://localhost/phone", IDNUM, IDPASS);
mync.onlineList = function(list) {
//填充List组件
mylist.labels = list;
};
}
server端
application.onAppStart=function(){
trace("------onAppStart----")
this.onlineList=[]
}
application.onConnect=function(newClient,IDNUM,IDPASS){
trace("------user onconnected------")
newClient.IDNUM=IDNUM
//newClient.IDPASS=IDPASS
//处理在线数组(push)
this.onlineList.push(IDNUM)
this.acceptConnection(newClient);
//广播给client
for(var i=0;i<this.clients.length;i++){
this.clients[i].call("onlineList",null,this.onlineList)
}
}
application.onDisconnect = function (newClient){
trace("------user disconnected------");
//处理在线数组(splice)
for(var i=0;i<=this.clients.length;i++){
if(this.onlineList[i]==newClient.IDNUM){
this.onlineList.splice(i,1)
}
}
//广播
for(var i=0;i<this.clients.length;i++){
this.clients[i].call("onlineList",null,this.onlineList)
}
};
trace("------onAppStart----")
this.onlineList=[]
}
application.onConnect=function(newClient,IDNUM,IDPASS){
trace("------user onconnected------")
newClient.IDNUM=IDNUM
//newClient.IDPASS=IDPASS
//处理在线数组(push)
this.onlineList.push(IDNUM)
this.acceptConnection(newClient);
//广播给client
for(var i=0;i<this.clients.length;i++){
this.clients[i].call("onlineList",null,this.onlineList)
}
}
application.onDisconnect = function (newClient){
trace("------user disconnected------");
//处理在线数组(splice)
for(var i=0;i<=this.clients.length;i++){
if(this.onlineList[i]==newClient.IDNUM){
this.onlineList.splice(i,1)
}
}
//广播
for(var i=0;i<this.clients.length;i++){
this.clients[i].call("onlineList",null,this.onlineList)
}
};