1

欢迎提出一些建议。这是我在输出中的错误...ArgumentError: Error #2126: NetConnection对象必须连接在flash.net::NetStream/ctor()at flash.net::NetStream()。这让我疯狂!我一直在调整我的代码,但仍然无法弄清楚。以下是我的代码,我不会向您展示它太长:如果您能确定我哪里出错了。

 var nc:NetConnection = new NetConnection();

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

nc.connect("rtmfp://localhost/appName");

 function netHandler(event:NetStatusEvent):void{
    switch(event.info.code){
        case "NetConnection.Connect.Success":
        trace("connecting.....");
        break;

        case "NetConnection.Connect.Failed":
        trace("Unable to connect up");
        break;

        case "NetConnection.Connect.Rejected":
        trace("Whoops");
            break;
        }
}

var ns:NetStream = new NetStream(nc);

ns.publish("live", "recording");

var cam:Camera = Camera.getCamera();
cam.setMode(540, 320, 15);
cam.setQuality(0, 80);
ns.attachCamera(cam);

cam.addEventListener(StatusEvent.STATUS, statusHandler);

var vid:Video = new Video();
vid.width = cam.width;
vid.height = cam.height;
vid.attachCamera(cam);

var mic:Microphone = Microphone.getMicrophone();
mic.setSilenceLevel(0, 2000);
mic.framesPerPacket = 1;
mic.codec = SoundCodec.SPEEX;
mic.gain = 50;
ns.attachAudio(mic);
4

1 回答 1

0

netConnection 需要一些时间来建立,但脚本在连接时不会停止,这就是为什么你有 netHandler 函数。

因此,您必须在触发 netStatusEvent "NetConnection.Connect.Success" 后设置您的 netStream。

您的 netHandler 函数应如下所示:

function netHandler(event:NetStatusEvent):void{
    switch(event.info.code){
        case "NetConnection.Connect.Success":
        trace("connecting.....");
        setupNetStream();
        break;

        case "NetConnection.Connect.Failed":
        trace("Unable to connect up");
        break;

        case "NetConnection.Connect.Rejected":
        trace("Whoops");
        break;
    }
}
function setupNetStream():void {
    ns = new NetStream(nc);
    // ...
}
于 2013-09-12T00:26:28.223 回答