[FMS]一步一步学Flash Media Server(四)
今天我们讲一个非常简单的多人聊天功能,同样我们也没有服务端代码,今天要用到一个新东西----SharedObject ?
package
?net.smilecn.chat{
???? ???? import ?flash.display.Sprite; ???? ?flash.net.NetConnection; ???? ?flash.net.SharedObject; ???? ?flash.events.NetStatusEvent; ???? ?flash.events.SyncEvent; ???? ?flash.events.MouseEvent; ???? ?fl.controls.TextArea; ???? ?fl.controls.Button; ???? ?fl.controls.TextInput; ???? ???? public ? class ?Chat? extends ?Sprite{ ???????? ???????? private ?var?nc:NetConnection; ???????? ?var?rtmpUrl:String? = " rtmp://localhost/chat ; ???????? ?var?button:Button; ???????? ?var?textArea:TextArea; ???????? ?var?textInput:TextInput; ???????? ?var?chatMsg_so:SharedObject; ???????? ?var?userName:String? user001 ; ???? ???????? ?function?Chat(): void { ????????????textArea new ?TextArea(); ????????????textArea.setSize?( 200 , 300 ); ????????????textArea.move?( 20 ); ????????????addChild?(textArea); ????????????textInput ?TextInput(); ????????????textInput.width? 140 ; ????????????textInput.move?( 330 ); ????????????addChild?(textInput); ????????????button ?Button(); ????????????button.width 50 ; ????????????button.label 发送 ; ????????????button.move?( 170 ); ????????????addChild(button); ????????????button.addEventListener?(MouseEvent.CLICK,sendMsg); ???????????? ???????????? ????????????nc ?NetConnection(); ????????????nc.addEventListener?(NetStatusEvent.NET_STATUS,netStatusHandler); ????????????nc.connect?(rtmpUrl); ????????} ???????? ???????? ?function?netStatusHandler(event:NetStatusEvent): { ???????????? if (event.info.code? == NetConnection.Connect.Success ){ ????????????????chatMsg_so SharedObject.getRemote( chatMsg false ); ????????????????chatMsg_so.connect?(nc); ????????????????chatMsg_so.addEventListener?(SyncEvent.SYNC,checkSO); ????????????} ????????} ???????? ???????? ?function?checkSO?(event:SyncEvent): { ????????????? for ?(var?i:uint;?i < event.changeList.length;?i ++ ) ?????????????{ ???????????????????? switch ?(event.changeList[i].code) ????????????????????{ ???????????????????????? case clear ?: ????????????????????????????trace( ); ???????????????????????????? break ; ???????????????????????? success ?: ?????????????????????????????trace?(chatMsg_so.data.msg); ????????????????????????????? ; ???????????????????????? change ?: ?????????????????????????????textArea.appendText?(chatMsg_so.data.msg? + ); ????????????????????????????? ; ???????????????????} ?????????????} ????????} ???????? ???????? ?function?sendMsg?(e:MouseEvent): { ?????????????chatMsg_so.setProperty?( msg : ?textInput.text); ?????????????textArea.appendText?(userName? ?textInput.text? ); ?????????????textInput.text? "" ; ????????} ????} ???? } 转载:http://blog.csdn.net/arrowyoung/article/details/2421965 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |