Skip to main content
Participant
October 30, 2006
Question

ArgumentError: Error #2126: NetConnection object must be connected.

  • October 30, 2006
  • 2 replies
  • 3889 views
I have a windows xp computer and a windows 2003 server computer connected with a single network cable. I am running Flash Media Server on the server computer. My Flex Builder 2 application can connect to the Flash Media Server on the other computer, but I always get the following error when trying to use NetStream:

nc.connect("rtmp://pb.local:1935/flexmediaservertest");

nsPublish = new NetStream(nc);
....

ArgumentError: Error #2126: NetConnection object must be connected.

What might be causing this error?
    This topic has been closed for replies.

    2 replies

    Inspiring
    October 31, 2006
    sorry about my last piece of code.... i forgot you are coding in AS3 - have
    some trickies.... but the logic still same... is a good chooice, always, make sure you have succeded connection.....


    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;

    private function init():void{
    // Create the NetConnection and listen for NetStatusEvent and SecurityErrorEvent events
    nc = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
    nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
    nc.connect("rtmp://pb.local:1935/flexmediaservertest");
    }

    private function netStatus(event:NetStatusEvent):void {
    trace("netStatus: " + event);
    var info:Object = event.info;
    trace(info.code);
    if (info.code == "NetConnection.Connect.Success") {
    // lots more code here...
    // CALL YOUR PUBLISH FUNCTION HERE.
    }
    }

    private function netSecurityError(event:SecurityErrorEvent):void {
    trace("netSecurityError: " + event);
    }



    I hope that's all....
    thedavidAuthor
    Participant
    November 2, 2006
    Thanks, yes I have it working now. But still one problem:-

    When running a Flex Builder 2 application in Internet Explorer and when disconnecting the client application's video stream from the Flash Media Server and closing the Internet Explorer Browser, the Internet Explorer Process continues to run in the background, ie: you can see it using Task Manager and must be terminated manually. So after testing the application several times, I have several instances of Internet Explorer all running in the background. Is there a cure for this?
    thedavidAuthor
    Participant
    November 4, 2006
    quote:

    Originally posted by: thedavid
    Thanks, yes I have it working now. But still one problem:-

    When running a Flex Builder 2 application in Internet Explorer and when disconnecting the client application's video stream from the Flash Media Server and closing the Internet Explorer Browser, the Internet Explorer Process continues to run in the background, ie: you can see it using Task Manager and must be terminated manually. So after testing the application several times, I have several instances of Internet Explorer all running in the background. Is there a cure for this?


    Apologies, this turned out to be a Windows XP faulty installation problem.
    Inspiring
    October 30, 2006
    do you watch the onStatus event? Try something like this:

    nc = new NetConnection();
    nc.onStatus = function(info) {
    // trace("Level: " + info.level + " Code: " + info.code);
    if (info.code == "NetConnection.Connect.Success") {
    //trace("--- connected to: "+this.uri);

    nsPublish = new NetStream(nc);

    } else if (info.code == "NetConnection.Connect.Failed" || info.code == "NetConnection.Connect.Closed") {
    trace("--- No connection to app");
    }
    };
    nc.connect("rtmp://pb.local:1935/flexmediaservertest");
    thedavidAuthor
    Participant
    October 31, 2006
    Thanks for the reply. I'll try that and let you know what happens.
    thedavidAuthor
    Participant
    October 31, 2006
    After banging my head against the computer for 3 days, I finally got my application working, but not with Flex Builder 2. I got it workin with Flash 8. There must be some problem between Actionscript3 and FMS2.

    I think the problem lies with NetStream in ActionScript3.

    private var nc:NetConnection;
    private var nsPublish:NetStream;
    .
    .

    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
    .
    .

    nc = new NetConnection();

    nc.connect("rtmp://pb.local:1935/flexmediaservertest"");
    nc.proxyType = "best";
    nsPublish = new NetStream(nc); ********************** this produces the connection error.
    .
    .

    I can see the application connected to the server using the Flash Media Server console. Somehow it does not like the NetStream command.