Recording Video with Development Server

Howdy folks,
I’m using development server and Flash CS3. Trying to write a script that will show live webcam in the flash movie and also let the server record it as an flv file. I can’t however figure out where I’m going wrong with my code - I’m quite new to AS3. The code is below followed by the output message.

 
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/rectest1");
var ns:NetStream = new NetStream(nc);
if(Camera.names.length > 0)
{
 var cam:Camera = Camera.getCamera();
}
else
{
 trace("user has no camera");
}
var live:Video = new Video();
live.attachCamera(cam);
ns.attachCamera(cam);
addChild(live);
ns.publish("random","record");

Here’s the output message:

 
ArgumentError: Error #2126: NetConnection object must be connected.
 at flash.net::NetStream/flash.net:NetStream::construct()
 at flash.net::NetStream$iinit()
 at Untitled_fla::MainTimeline/Untitled_fla::frame1()

Media/Development server shows a client connecting but nothing else happens, any help greatly appriciated.
thanks, dj