Skip navigation
Currently Being Moderated

Argument error #2126

Sep 13, 2013 1:45 PM

Hello Guys, I would appreciate some advice. I am trying to connect to my webcam but I keep receiving this error message.

I have been tweaking around my code for hours but problem keeps persisting.  I don't know where is the problem? Thanks in advance

 

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

    at flash.net::NetStream/construct()

    at flash.net::NetStream()

Here is my code:

var nc:NetConnection = new NetConnection();

 

nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

 

nc.connect("rtmfp://localhost/myAppName);

 

function netHandler(event:NetStatusEvent):void{

   switch(event.info.code)

     case "NetConnection.Connect.Success":

    trace("Connecting up");

    break;

 

   case "NetConnection.Connect.Failed":

   trace("Unable to Connect");

   break;

 

  case "NetConnection.Connect.Rejected":

  trace("Ouch");

  break;

 

var ns:NetStream = new NetStream(nc);

 

ns.publish("live", "streaming");

 

var cam:Camera = Camera.getCamera();

cam.setQuality(0, 80);

cam.setMode(500, 300, 15);

ns.attachCamera(cam);

 

cam.addEventListener(StatusEvent.STATUS, statusHandler);

 

var vid:Video = new Video();

vid.height = cam.height;

vid.width = cam.width;

vid.attachCamera(cam);

addChild(vid);

 

var mic:Microphone = Microphone.getMicrophone();

mic.setSilenceLevel(0, 2000);

mic.framesPerPacket = 1;

mic.codec = SoundCodec.SPEEX;

mic.gain = 50;

ns.attachAudio(mic);

 

mic.addEventListener(StatusEvent.STATUS, micStatus);

 

////Verifying that the cameras are installed
if (cam == null)
{
    trace("User has no cameras installed.");
}
else
{
    trace("User has at least 1 camera installed.");
}


//Detecting permission for camera access
function statusHandler(event:StatusEvent):void
{
    switch (event.code)
    {
        case "Camera.Muted":
            trace("User clicked Deny.");
            break;
        case "Camera.Unmuted":
            trace("User clicked Accept.");
            break;
    }
}

//Camera lists names
for (var i:int = 0; i < Camera.names.length; i++) {
    trace(Camera.names[i]);
}

//microphone event
function micHandler(event:StatusEvent):void
{
    if (event.code == "Microphone.Unmuted")
    {
        trace("Microphone access was allowed.");
    } 
    else if (event.code == "Microphone.Muted")
    {
         trace("Microphone access was denied.");
    }
}

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points