I am wondering if anyone can help resolve my problem. I am using the NetConnection and NetStream classes to connect to a webcam feed using Flash Media Server. However, this appears every time in my output:
ArgumentError: Error #2126: NetConnection object must be connected. at flash.net::NetStream/ctor() at flash.net::NetStream()
I have tweaked around with the code but to no avail.
Any ideas as to why this isn't working? Here is the (I think relevant) code:
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;
}