1. 安装 Flash Media Development Server 4.5 并启动服务
2. 安装Flash Builder
3. 用Flash Builder 文件 -> 新建 -> Flex手机项目 -> HelloWorld
4. 修改HelloWorldView.mxml代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="initView()" title="主页视图">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import flash.events.MediaEvent;
import flash.net.NetConnection;
import flash.net.Responder;
import mx.rpc.events.ResultEvent;
private var rso:SharedObject;
private var nc:NetConnection;
private function initView():void{
conBt.label="connect";
}
protected function conBt_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
if(conBt.label == "connect"){
trace("Connect...");
nc = new NetConnection();
nc.connect("rtmp://192.168.0.100/HelloWorld");//rtmp://localhost/HelloWorld");
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatusHandler);
conBt.label = "disconnect";
}else {
trace("Disconnecting...");
nc.close();
conBt.label = "connect";
}
}
private function onNetStatusHandler(evt:NetStatusEvent):void{
switch(evt.info.code){
case "NetConnection.Connect.Success":
trace("NetConnection.Connect.Success");
rso = SharedObject.getRemote("userInfo", nc.uri, false);
rso.connect(nc);
rso.addEventListener(SyncEvent.SYNC, onSyncHandler);
break;
case "NetConnection.Connect.Fail":
trace("NetConnectionFail");
break;
}
}
private function onSyncHandler(e:SyncEvent):void{
trace("onSyncHandler() ....");
for(var chng:uint;chng<e.changeList.length;chng++){
switch(e.changeList[chng].code){
case "change":
updateAllClientMsg();
break;
case "clear":
break;
case "success":
break;
default:
break;
}
}
}
private function updateAllClientMsg():void{
soList.text+=rso.data.msg+"\n";
}
private function addDataToShareObject():void{
rso.setProperty("msg",msgText.text);
soList.text+=msgText.text+"\n";
msgText.text="";
}
]]>
</fx:Script>
<s:VGroup width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
<s:TextArea id="soList" width="300" height="120"/>
<s:TextInput id="msgText"/>
<s:Button label="send Msg" width="150" click="addDataToShareObject();"/>
<s:Button id="conBt" y="10" width="150" click="conBt_clickHandler(event)"/>
</s:VGroup>
</s:View>
5.FMS安装目录C:\Program Files\Adobe\Flash Media Server 4.5\applications创建文件夹HelloWorld
6.连上Android手机,确认WiFi打开,并能正常访问FMS;配置Flash Builder HelloWorld工程 运行方式 -> 运行配置 -> 启动方法:在设备上; 目标平台:Google Android
7. 配置Flash Builder HelloWorld工程 运行方式 -> 运行配置 -> 启动方法:在桌面上(Motorola Droid Pro)
8.运行Flash Builder HelloWord工程,先点击connect按钮,再输入文字并发送。文字聊天测试通过。