flex连接fms

发布时间:2009-05-22 14:43:00 阅读:919次

flex.mxml

<?xml version="1.0" encoding="utf-8"?>
<!--http://www.cnblogs.com/beniao/archive/2009/02/27/1392115.html-->
<!--http://livedocs.adobe.com/flashmediaserver/3.0/docs/help.html-->
<!--http://www.adobe.com/cfusion/tdrc/index.cfm?product=flashmediaserver&loc=en_us-->
<!--http://hi.baidu.com/webok/blog/item/a1f5bbd3ee23d13c960a164b.html-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
       <![CDATA[
            import mx.controls.Alert;
            //Flex与FMS建立连接的对象
            private var nc:NetConnection;
            //FMS服务器的地址,使用rtmp协议
            private var rtmpUrl:String="rtmp://localhost/firstFMS";
         //D:Program FilesAdobeFlash Media Server 3.5applicationsfirstFMS  
            //当Flex应用程序启动的时候就建立与FMS服务器的连接
           internal function goconnect():void
         
           {
          
               nc = new NetConnection();
                nc.connect(rtmpUrl);
                nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
               nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,onAsyncErrorHandler);
              
               //Alert.show("a");
              
            }
         private function onClickHandler(evt:MouseEvent):void
           {
                trace("正在连接FMS服务器");
              
              nc = new NetConnection();
              nc.connect("rtmp://localhost/firstFMS");
              nc.client=this;
              nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatusHandler);
                nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,onAsyncErrorHandler);
           }
      
           private function onNetStatusHandler(evt:NetStatusEvent):void
            {
                switch (evt.info.code)
               {
                   case "NetConnection.Connect.Success":
                       Alert.show("成功连接FMS服务器!");
                       break;
                  case "NetConnection.Connect.Rejected":
                       Alert.show("访问FMS服务器权限不足,连接被拒绝!");
                       break;
                   case "NetConnection.Connect.InvalidApp":
                        Alert.show("指定的应用程序名称没有找到");
                       break;
                    case "NetConnection.Connect.Failed":
                       Alert.show("连接失败!");
                        break;
                   case "NetConnection.Connect.AppShutDown":
                       Alert.show("服务器端应用程序已经关闭(由于资源耗用过大等原因)或者服务器已经关闭!");
                       break;
                   case "NetConnection.Connect.Closed":
                        Alert.show("与FMS的连接中断!");
                        break;
               }
           }
          
           private function onAsyncErrorHandler(evt:AsyncErrorEvent):void
          {
         
          }
   ]]>
   </mx:Script>
    <mx:Button x="135" y="89" label="Button" click="goconnect()" fontSize="12" fontWeight="normal"/>
</mx:Application>

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:flex随机数

转载请注明:flex连接fms 出自老鄢博客 | 欢迎分享