# Argument error #2126

**URL:** <https://forum.kirupa.com/t/argument-error-2126/331646>\
**Category:** flash\
**Created:** [September 16, 2013, 3:21pm UTC](https://forum.kirupa.com/t/argument-error-2126/331646 "2013-09-16T15:21:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![quest20](https://avatars.discourse-cdn.com/v4/letter/q/a87d85/32.png) [@quest20](https://forum.kirupa.com/u/quest20)\
**Post date:** [September 16, 2013, 3:21pm UTC](https://forum.kirupa.com/t/argument-error-2126/331646/1 "2013-09-16T15:21:37Z")

</div>

Hello Guys, I would appreciate some advice. I am  
trying to connect to my [FONT=Verdana][SIZE=2][COLOR=#0000ff]webcam[/COLOR][/SIZE][/FONT]  
but I keep receiving this error message argument error#2126

I have been tweaking around my code for hours but problem keeps persisting. I don’t know where is the problem?  
This is my code below:

Thanks in advance

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

at [flash.net](http://flash.net)::NetStream/construct()

at [[COLOR=blue][COLOR=blue !important][FONT=verdana][COLOR=blue !important][FONT=verdana]flash[/FONT][/COLOR][/FONT][/COLOR][/COLOR]](http://www.kirupa.com/forum/#).net::NetStream()

Here  
is my code:

//Establishing a FMS connection  
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 [[COLOR=blue][COLOR=blue !important][FONT=verdana][COLOR=blue !important][FONT=verdana]Video[/FONT][/COLOR][/FONT][/COLOR][/COLOR]](http://www.kirupa.com/forum/#)();

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.[[COLOR=blue][COLOR=blue !important][FONT=verdana][COLOR=blue !important][FONT=verdana]codec[/FONT][/COLOR][/FONT][/COLOR][/COLOR]](http://www.kirupa.com/forum/#)  
= 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\*);  
}

//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.”);  
}  
}
