fms+flex==>hello world!
空的时候温习了一下fms的hello world
//按钮点击进行连接 function btnConnClick(evt:MouseEvent) { if (nc==null) { nc=new NetConnection(); //状态变化结果 nc.addEventListener(NetStatusEvent.NET_STATUS,connHandler); if(nc.connect(url_ok,"aa")){ lblResult.text="连接fms中。。。。"; }else{ //lblResult.text="地址错误"; } } } //断开连接 function btnDisConnClick(evt:MouseEvent) { if (nc!=null) { nc.close(); nc=null; } } //连接状态 function connHandler(evt:NetStatusEvent) { trace(evt.info.code); switch (evt.info.code) { case "NetConnection.Connect.Closed" : Alert.show("成功关闭连接"); break; case "NetConnection.Connect.Failed" : Alert.show("连接尝试失败"); break; case "NetConnection.Connect.Success" : Alert.show("连接尝试成功"); var resp:Responder = new Responder(onReply); nc.call("serverHelloMsg", resp, "Hi FMS!");//调用服务端的serverHelloMsg的方法 break; case "NetConnection.Connect.Rejected" : lblResult.text="连接尝试没有访问应用程序的权限"; //注意这里,服务器拒绝你的情况,如果遭到拒绝,将会调用两次mync.onStatus, //第1次"NetConnection.Connect.Rejected" //第2次"NetConnection.Connect.Closed" Alert.show("遭到服务器拒绝"); Alert.show("服务器返回信息:"+evt.info.application.msg); break; default : lblResult.text=evt.info.code; break; } } function onReply(e:Object) { trace("服务端返回内容:" + e); lblResult.text = e.toString(); }
//实例 application.onAppStart = function() { trace("启动") //this.chatRSO = SharedObject.get('chatRSO',true); //user list this.userListArray=new Array(); }; //请求连接 application.onConnect=function(client,clientName){ //检查重名 if(clientName=="fms"){ application.rejectConnection(client,{msg:"被拒绝"}); return ; }else{ application.acceptConnection(client); client.clientName=clientName; } //欢迎 client.serverHelloMsg=function(helloStr){ trace(helloStr); return "hellow,"+helloStr+" !!!"; } }