`
唐朝
  • 浏览: 257982 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

FMS回调FLEX端的Function

    博客分类:
  • flex
阅读更多

网络上找了很久这个资料,总算被解决了。

1.在FMS下新建一个应用callclient(我的目录D:\Macromedia\Flash Media Server 2\applications),重新启动FMS

2.编写服务器端代码main.asc

js 代码
  1. application.onAppStart = function()   
  2. {   
  3.        
  4. }   
  5.   
  6. application.onConnect = function(newClient, userName)   
  7. {   
  8.     newClient.name = userName;   
  9.     application.acceptConnection(newClient);   
  10.     newClient.call("getServerMsg"null"欢迎"+userName+"的到来~~");   
  11. }  

 

3.编写客户端代码callclient.mxml

xml 代码
  1. <!---->xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp();">  
  3.     <mx:TextInput x="160" y="157" id="txtUserName"/>  
  4.     <mx:Button x="332" y="157" label="Get Server Message" fontWeight="bold" fontStyle="italic" click="connectServer();"/>  
  5.     <mx:Script>  
  6.         <!----> 
  7.             import mx.collections.ArrayCollection;   
  8.                 import flash.net.*;  
  9.                 import flash.events.*;  
  10.                 import flash.utils.*;  
  11.                 import mx.controls.*;  
  12.                 import mx.core.UIComponent;  
  13.                   
  14.                 NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;  
  15.                   
  16.                 private var nc:NetConnection;  
  17.                   
  18.                 private function initApp():void                                   
  19.                 {  
  20.                     nc = new NetConnection();                 
  21.                     nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);  
  22.                     nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);  
  23.                 }  
  24.                   
  25.                 private function netStatus(event:NetStatusEvent):void   
  26.                 {  
  27.                     var connStatus:String = event.info.code;  
  28.                     Alert.show(connStatus);  
  29.                 }  
  30.                   
  31.                 private function netSecurityError(event:SecurityErrorEvent):void {  
  32.                     Alert.show("netSecurityError: " + event);  
  33.                 }  
  34.                   
  35.                 private function connectServer():void  
  36.                 {  
  37.                     nc.connect("rtmp://localhost/callclient", txtUserName.text);  
  38.                     nc.client = this;  
  39.                 }  
  40.                   
  41.                 public function getServerMsg(serverMsg:String):void  
  42.                 {  
  43.                     Alert.show("The Message from Server:"+serverMsg);  
  44.                 }  
  45.         ]]>  
  46.     mx:Script>  
  47. mx:Application>  

 

4.运行该flex程序,测试成功,吃饭去~~~

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics