Occasionally I'm getting an unhanded NetStatusEvent
when using NetConnection
to connect to a Red5 server:
Error #2044: Unhandled NetStatusEvent:. level=error, code=NetConnection.Call.Failed
This is how I am connecting (the only place where NetConnection.connect()
is called):
public function Connect(callBack:Function = null):void
{
if (IsConnected())
{
if (callBack != null)
{
callBack.call();
}
}
else // Not connected
{
netConnect.addEventListener(NetStatusEvent.NET_STATUS, function(e:NetStatusEvent):void
{
// OnConnect called whenever there is a net status event
OnConnect(e, callBack);
netConnect.removeEventListener(NetStatusEvent.NET_STATUS, arguments.callee);
});
try
{
// Attempt to connect to Media Server
netConnect.connect(MEDIA_SERVER_URI, true);
}
catch(error:Error)
{
logger.LogError("NetConnection.connect threw an exception.", error);
}
}
}
I am adding an event listener for NetStatusEvent.NET_STATUS
. How is it possible that sometimes my listener called?
You're removing your listener in your NetStatusEvent
handler. You should keep it until the connection is closed. This is why NetStatusEvent
is only handled once before its listener is removed. Any other than first event will throw that error.
So remove netConnect.removeEventListener(NetStatusEvent.NET_STATUS, arguments.callee);
NetConnection
dispatches that event quite a lot, depending on what is happening. You have to handle the event until every time. For a list of possible values of the info
property visit this Link. There's also a little example of how to handle the event at the end of the page.