·您当前的位置:首页 > 技术教程 > Rtmp技术 >

[FMS]FMS应用之文本对话聊天代码示例

时间:2012-10-23 23:09cnblogs.com
[FMS]FMS应用之文本对话聊天代码示例,FMS应用,FMS聊天代码
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
  3.                xmlns:s="library://ns.adobe.com/flex/spark" 
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()"> 
  5.     <s:layout> 
  6.         <s:BasicLayout/> 
  7.     </s:layout> 
  8.     <fx:Script> 
  9.         <![CDATA[ 
  10.             private var nc:NetConnection; 
  11.             private var so:SharedObject; 
  12.              
  13.             private function init():void 
  14.             { 
  15.                 nc = new NetConnection(); 
  16.                 nc.connect("rtmp://cuplayer.com/vod"); 
  17.                 nc.client = this; 
  18.                 nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus); 
  19.             } 
  20.              
  21.             private function onNetStatus(evt:NetStatusEvent):void 
  22.             { 
  23.                 trace(evt.info.code); 
  24.                 if(evt.info.code=="NetConnection.Connect.Success") 
  25.                 { 
  26.                     so = SharedObject.getRemote("myMsg",nc.uri,false); 
  27.                     so.addEventListener(SyncEvent.SYNC,onSYNC); 
  28.                     so.connect(nc); 
  29.                 } 
  30.             } 
  31.              
  32.             private function onSYNC(evt:SyncEvent):void 
  33.             { 
  34.                 for(var i:uint=0;i<evt.changeList.length;i++) 
  35.                 { 
  36.                     switch(evt.changeList[i].code) 
  37.                     { 
  38.                         case "change": 
  39.                             updateList(); 
  40.                             break; 
  41.                         case "clear": 
  42.                             break; 
  43.                         case "success": 
  44.                             break; 
  45.                         default: 
  46.                             break; 
  47.                     } 
  48.                 } 
  49.             } 
  50.              
  51.             private function updateList():void 
  52.             { 
  53.                 msgList.text += so.data.msg+"\n"; 
  54.             } 
  55.              
  56.             protected function onClick(event:MouseEvent):void 
  57.             { 
  58.                 so.setProperty("msg",txtInput.text); 
  59.                 msgList.text+=txtInput.text+"\n"; 
  60.                 txtInput.text=""; 
  61.             } 
  62.              
  63.             public function onBWDone():void{} 
  64.         ]]> 
  65.     </fx:Script> 
  66.     <fx:Declarations> 
  67.         <!-- 将非可视元素(例如服务、值对象)放在此处 --> 
  68.     </fx:Declarations> 
  69.     <s:TextArea id="msgList" x="173" y="37" width="300" height="150"/> 
  70.     <s:TextInput id="txtInput" x="173" y="218" width="209"/> 
  71.     <s:Button id="btnPost" x="399" y="219" label="按钮" click="onClick(event)" /> 
  72. </s:Application> 

 

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器