Flash Media Server 简称 FMS,目前版本号已经是3.5,FMS 可以作为提供诸如视频会议,网络游戏等交互式应用的服务平台,尤其在多媒体方面表现尤为出色。 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" creationComplete="init()"> <fx:Script> <!--[CDATA[ import cn.ipanel.fmsdemo.vo.Message; import mx.formatters.DateFormatter; import mx.collections.ArrayCollection; import mx.controls.Alert; private var netConnection:NetConnection; private var serverApp:String="rtmp://192.168.33.79/myApp"; private var talkSO:SharedObject; private function init():void{ netConnection=new NetConnection(); netConnection.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); netConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler); netConnection.connect(serverApp); sendBtn.addEventListener(MouseEvent.CLICK,sendBtn_clickHandler); } private function netStatusHandler(e:NetStatusEvent):void{ trace(e.info.code); if(e.info.code=="NetConnection.Connect.Success"){ talkSO=SharedObject.getRemote("talk",netConnection.uri,false); talkSO.connect(netConnection); talkSO.addEventListener(SyncEvent.SYNC,syncHandler); talkSO.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler); }else{ Alert.show("contection failed"+e.info.code); } } private function asyncErrorHandler(e:AsyncErrorEvent):void{ trace(e.type); } private function syncHandler(e:SyncEvent):void{ trace(e.type); textAreaContent.text=""; if(talkSO.data.msgList!=null){ var tmp:ArrayCollection = new ArrayCollection(); convertArrayCollection(tmp,talkSO.data.msgList as ArrayCollection); var dateFormatter:DateFormatter=new DateFormatter(); dateFormatter.formatString="HH:NN:SS"; for(var i:int = 0;i<tmp.length;i++) { var message:Object = tmp.getItemAt(i) as Object; var timeString:String = dateFormatter.format(message.time); var fullMsg:String = message.nickname + " at " + timeString + " said:" + message.msg; textAreaContent.text = textAreaContent.text+fullMsg+"/n"; } } } protected function sendBtn_clickHandler(event:MouseEvent):void { // TODO Auto-generated method stub var array:ArrayCollection = new ArrayCollection(); if(talkSO.data.msgList != null){ convertArrayCollection(array,talkSO.data.msgList as ArrayCollection); } var message:Message = new Message(); message.nickname=textInputName.text; message.msg=textInputMessage.text; message.time=new Date(); array.addItem(message); talkSO.setProperty("msgList",array); textInputMessage.text=""; } private function convertArrayCollection(arrayNew:ArrayCollection,arrayOld:ArrayCollection):void{ arrayNew.removeAll(); for(var i:int=0;i<arrayOld.length;i++){ arrayNew.addItemAt(arrayOld.getItemAt(i),i); } } ]]--> </fx:Script> <s:TextArea x="260" y="128" width="385" height="198" id="textAreaContent"/> <s:TextInput x="256" y="348" width="116" id="textInputName"/> <mx:Label x="389" y="352" text="说"/> <s:TextInput x="412" y="348" id="textInputMessage"/> <s:Button x="606" y="347" label="发送" id="sendBtn"/> </s:Application> package cn.ipanel.fmsdemo.vo { public class Message { public function Message() { } private var _nickname:String; private var _msg:String; private var _time:Date; public function get time():Date { return _time; } public function set time(v:Date):void { _time = v; } public function get msg():String { return _msg; } public function set msg(v:String):void { _msg = v; } public function get nickname():String { return _nickname; } public function set nickname(v:String):void { _nickname = v; } } } 好歹迈出一步了!