加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

文字聊天hello world 远端共享对象方式

发布时间:2020-12-15 18:34:21 所属栏目:百科 来源:网络整理
导读: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.adob

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 FilesAdobeFlash Media Server 4.5applications创建文件夹HelloWorld

6.连上Android手机,确认WiFi打开,并能正常访问FMS;配置Flash Builder HelloWorld工程 运行方式 -> 运行配置 -> 启动方法:在设备上; 目标平台:Google Android

7. 配置Flash Builder HelloWorld工程 运行方式 -> 运行配置 -> 启动方法:在桌面上(Motorola Droid Pro)

8.运行Flash Builder HelloWord工程,先点击connect按钮,再输入文字并发送。文字聊天测试通过。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读