Quick Tip: Working with NetStream

While working on my brand new P2P project I have come to some issues and solutions, that may help you with your projects. First thing, the NetStatusEvent codes. You may expect that codes are dispatched by the instance of the class they beigins with (e.g. “NetStream.Connect.Success” dispatched by NetStream), but in fact, this does not happen (“NetStream.Connect.Success” is dispatched by NetConnection). I bellieve its not a bug but a feature by flash player developer team. To make this work as expected you may do the following:

netConnection.addEventListener(type, onNetStatus);
        
function onNetConnectionNetStatus(event:NetStatusEvent):void
{
	switch(event.info.code){
		case "NetStream.Connect.Success":
			event.info.stream.dispatchEvent(event);
			break;
		...
	}
}

Read the rest of this entry »