我想知道是否有人可以幫助解決我的問題。我正在使用NetConnection和NetStream類使用Flash Media Server連接到網絡攝像頭饋送。但是,每次在我的輸出中都會出現:使用ActionScript編寫編程錯誤
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;
}