PDA

View Full Version : [AS3] RTMP question


PBFrO
01-25-2010, 05:54 PM
Hi all.

I'm stuck on a flash video problem and wondering if anyone can spot where I'm going wrong here. I've be able to do this in AS2 no problem, but for some reason AS3 is rejecting me here.


var _video:Video = new Video(600,338);
var _nc:NetConnection = new NetConnection();
_nc.connect("rtmp://myurl.com/vod/");
var _ns:NetStream = new NetStream(_nc);
_video.attachNetStream(_ns);


When I run that I get these two errors:


ArgumentError: Error #2126: NetConnection object must be connected.
at flash.net::NetStream/flash.net:NetStream::construct()
at flash.net::NetStream$iinit()
at VideoMC/::frame1()
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetConnection was unable to invoke callback onBWDone.
error=ReferenceError: Error #1069: Property onBWDone not found on flash.net.NetConnection and there is no default value.
at VideoMC/::frame1()


Any ideas? Thanks.

sparkdemon
01-26-2010, 01:59 PM
I guess you are using the flex video component. That causes some issues.

bowljoman
01-26-2010, 03:12 PM
no, he is not waiting for the connection to connect before he makes the netstream and calls.

sparkdemon
01-26-2010, 06:53 PM
aha!

sorry i did'nt notice the code posted. There must be a onStatus event handler to confirm the connection before you use netstream.

PBFrO
01-26-2010, 11:19 PM
Thanks for the responses. I went ahead and made sure the connection is made but now nothing happens. I traced out to see if the connection is made and i get success. I have it then try to play but nothing happens.


var nc:NetConnection;
var ns:NetStream;
var _video:Video = new Video(320,240);
var _dur:Number = new Number();
var _cur:String = new String();
addChild(_video);
_video.x = 200;
connect();
function connect()
{
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
nc = new NetConnection();
nc.client = this;
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://myurl.net/vod/");
}



function netStatusHandler(event:NetStatusEvent) {
if(nc.connected)
{
ns = new NetStream(nc);
_video.attachNetStream(ns);
_video.attachNetStream(ns);
ns.play("myclip");

}
}

MontyCoder
01-27-2010, 06:12 AM
try this
connect();
function connect()
{
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
nc = new NetConnection();
nc.client = this;
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.connect("rtmp://myurl.net/vod/media/");
}



function netStatusHandler(event:NetStatusEvent) {
if(event.info.code == "NetConnection.Connect.Success")
{
ns = new NetStream(nc);
_video.attachNetStream(ns);
_video.attachNetStream(ns);
ns.play("myclip");

}
}

PBFrO
01-27-2010, 05:32 PM
Finally got it to work!

Always a good thing when someone removes the file you're pointing at without telling you. :(

Thank you all very much on the advice for the checking the connected status.

bowljoman
01-28-2010, 04:40 PM
:d