Apache flex 链接flex应用程序中的网络摄像头

Apache flex 链接flex应用程序中的网络摄像头,apache-flex,actionscript,flash-builder,Apache Flex,Actionscript,Flash Builder,我在连接网络摄像头时遇到了一个非常奇怪的问题,我遇到了以下错误 ArgumentError:错误#2126:必须连接NetConnection对象。 在flash.net::NetStream/ctor()上 在flash.net::NetStream()上 以下是我在main.mxml中的代码 <fx:Script> <![CDATA[ import flash.media.Camera; import flash.media.Video;

我在连接网络摄像头时遇到了一个非常奇怪的问题,我遇到了以下错误

ArgumentError:错误#2126:必须连接NetConnection对象。 在flash.net::NetStream/ctor()上 在flash.net::NetStream()上

以下是我在main.mxml中的代码

 <fx:Script>
   <![CDATA[
       import flash.media.Camera;
       import flash.media.Video;
       import flash.net.NetConnection;
       import mx.core.UIComponent;
       import com.kahaf.plutay.* ;    

       private var inVideo:Video;
       private var outVideo:Video;
       private var inVideoWrapper:UIComponent;
       private var camera:Camera;
       private var mic:Microphone;
       private var inStream:NetStream;
       private var outStream:NetStream;

       private function defaultVideoMode(): void
       {
          VideoPanel.width = 726;
           VideoPanel.height = 494;
           inVideo.width = 726;
           inVideo.height = 494;
       }

       private function showInComingVideo():void
       {
           inVideo = new Video(VideoPanel.width,VideoPanel.height);
           inVideo.attachNetStream(inStream);
           inVideoWrapper = new UIComponent();
           inVideoWrapper.addChild(inVideo);
           VideoPanel.addElement(inVideoWrapper);
           defaultVideoMode();
        }


       private function setupVideo(event:MouseEvent): void
       {
           camera = Camera.getCamera();
           mic = Microphone.getMicrophone();
           mic.setLoopBack(false); 
           mic.setUseEchoSuppression(true);
           camera.setMode(640,480,20);
           camera.setQuality(65536,90);

           var conn:NetConnection = Connection.getConnection().conn;

           inStream = new NetStream(conn);
           inStream.play(conn);
           showInComingVideo();
       } 
   ]]>

在处理NetConnection和NetStreams时,这是正确的顺序:

  • 创建并建立网络连接(NetConnection.connect())
  • 等待NetConnection.Connect.Success事件(NetStatusEvent.NET_状态)
  • 创建NetStream并将连接的网络连接连接到它
  • 发布/播放您的流

  • 为什么要创建单例连接?这没用。其次,这个错误并不十分神秘。它用通俗易懂的英语说,你正在尝试将一个流连接到一个没有连接到任何东西的网络连接上……那么,你有什么建议我如何将它连接到网络?你需要先将它连接到服务器上。。。
    <s:Group x="283" y="330" width="234" height="149" id="VideoPanel" >
    </s:Group>
    <s:Button x="447" y="151" label="Click Me." click="setupVideo(event)"/>
    
    import flash.net.NetConnection;
    
    public class Connection extends NetConnection
    {
        public static var conObj:Connection;
        public var conn:NetConnection;
        public var target:Object;
        public var selector:Function;
    
        public function Connection()
        {
            conn = new NetConnection;
            target = null;
            selector = null;
            conn.client = this;
    }
    
        public static function getConnection():Connection
        {
            if(conObj == null)
            {
                conObj = new Connection();
            }
                return conObj;
        }
        }