我想知道是否有人可以帮助解决我的问题。我正在使用 NetConnection 和 NetStream 类连接到使用 Flash Media Server 的网络摄像头源。但是,这每次都会出现在我的输出中:
ArgumentError:错误 #2126:必须连接 NetConnection 对象。在 flash.net::NetStream/ctor() 在 flash.net::NetStream()
我已经调整了代码,但无济于事。
关于为什么这不起作用的任何想法?这是(我认为相关的)代码:
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.net.NetStream;
import flash.events.AsyncErrorEvent;
var nc:NetConnection = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
nc.connect("rtmfp://localhost//myUrlExample");
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.publish("myStream", "recording");
function netHandler(event:NetStatusEvent):void{
switch(event.info.code){
case "NetConnection.Connect.Success":
trace("Successs");
break;
case "NetConnection.Connect.Failed":
trace("Cannot connect to the server");
break;
case "NetConnection.Connect.Rejected":
trace("Ouch!");
break;
}
}
function asyncErrorHandler(event:AsyncErrorEvent):void{
//ignore error;
}