宜昌本地软件开发与弱电工程服务商
项目咨询 · 快速响应
您当前的位置: > 博客2 > Rtmp技术

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

2016-10-13 00:16:48 点击量:10 标签: 收藏本文

  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> 

 

ABOUT US
宜昌农人网络科技有限公司

我们是一家提供综合软件外包与弱电工程服务的技术公司。

业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。

公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室