flex连接fms

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>

    A+
发布日期:2009年05月22日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: