Skip to main content
mrweb2010
Known Participant
July 29, 2011
Question

Error when connecting to FMS using AS3

  • July 29, 2011
  • 1 reply
  • 1518 views

Hello,

I'm trying to stream my webcam to my FMS Server, using AS3, but I get this error message:

ArgumentError: Error #2126: NetConnection object must be connected.
    at flash.net::NetStream/construct()
    at flash.net::NetStream()
    at broadcatser_fla::MainTimeline/clickHandler()

     Here is my code:

    btnSart.addEventListener(MouseEvent.CLICK, clickHandler);
   
    function clickHandler(eventObj:MouseEvent):void
    {

        var camera:Camera = Camera.getCamera();
      
        camera.setMode(450, 233.9, 30);
     
        oVideo1.attachCamera(camera);


        addChild(oVideo1);
        //========== RTMP publishing==============
        var RTMP:String = "rtmp://*********************";

        var nTimer:Number;
        var index:Number = 0;
       
        var nc:NetConnection = new NetConnection();


        nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);


        nc.client = this;


        nc.connect(RTMP);


        var ns:NetStream = new NetStream(nc);


        nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);

        ns.publish("mystream");
    }
   
    function netStatus(event:NetStatusEvent):void
    {
        trace("netStatus: " + event);
        var info:Object = event.info;
        trace(info.code);
info = event.info;
                    switch (info.code) {
                        case "NetConnection.Connect.Success":
                            trace("CONNECTION SUCCES");
                            break;
                        case "NetConnection.Connect.Failed":
                            trace("CONNECTION FAILED");
                            break;
                        case "NetConnection.Connect.Rejected":
                            trace("CONNECTION REJECTED");
                            break;
                        case "NetConnection.Connect.Closed":
                            trace("GESLOTEN");
                            break;
                        case "NetStream.Play.Start":
                            trace ("GESTART");
                            break;
                        default:
                            trace("Some Error occured.");
                        }
    }

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

I don't know where is the problem.

Thanks in advance

    This topic has been closed for replies.

    1 reply

    calmchessplayer
    Inspiring
    August 1, 2011

    Well from first glance your code looks like it might work I haven't put it in CS5 and debugged it so my guess is your rtmp string is incorrect Please place a fake IP address in your current RTMP string and show it to me please.

    mrweb2010
    mrweb2010Author
    Known Participant
    August 5, 2011

    Thanks for ur reply , I found out the problem. I moved ns.publish("mystream") command to netStatus fucntion. the error happened because I tried to publish the stream before the connection happens.

    function netStatus(event:NetStatusEvent):void
        {
            trace("netStatus: " + event);
            var info:Object = event.info;
            trace(info.code);
    info = event.info;
                        switch (info.code) {
                            case "NetConnection.Connect.Success":

                                ns.publish("mystream");

                                trace("CONNECTION SUCCES");
                                break;
                            case "NetConnection.Connect.Failed":
                                trace("CONNECTION FAILED");
                                break;
                            case "NetConnection.Connect.Rejected":
                                trace("CONNECTION REJECTED");
                                break;
                            case "NetConnection.Connect.Closed":
                                trace("GESLOTEN");
                                break;
                            case "NetStream.Play.Start":
                                trace ("GESTART");
                                break;
                            default:
                                trace("Some Error occured.");
                            }
        }

    Thanks