Implementing buffer in video recording app

Hi,

I am developing an webcam recorder and would like to implement the buffer concept in order to avoid the dropping of video frames.

Can any one please help in implementing it.

Find below code which I have implemented so far.

public var camera:Camera;
public var mic:Microphone;
public var nc:NetConnection;
public var ns:NetStream;	
public var nsOutGoing:NetStream;
var bufferCheckTimer:Timer=new Timer(60);

Now after getting “NetConnection.Connect.Success”, following gets called:

nsOutGoing = new NetStream(nc);
camera=Camera.getCamera();

var nsOutGoingObject:Object = new Object();
nsOutGoing.client = nsOutGoingObject; 
nsOutGoing.bufferTime = 60; 
nsOutGoingObject.onMetaData = handleOnMetadata;	
nsOutGoingObject.onPlayStatus = handleOnPlayStatus; 
myWebcam.attachCamera(camera);
nsOutGoing.attachCamera(camera);

camera.addEventListener(StatusEvent.STATUS, handleCameraStatus);

//Now Setting up the microphone and adding it to nsOutGoing object.

Now, once user clicks on the record button, following code is called:

nsOutGoing.publish(fileName, "record");
// Start the timer to update the buffer 
camera.addEventListener("timer", handleBufferCheck); 
bufferCheckTimer.start();

Now, when user clicks on stop button, following code is called:

if (nsOutGoing != null) 
{ 
nsOutGoing.attachAudio(null); 
nsOutGoing.attachCamera(null); 
videoPlayer.attachCamera(null); 
}

// Here's the timer's handler that continually checks the BufferLength 

private function handleBufferCheck(e:TimerEvent):void 
{ 
if (nsOutGoing != null) 
{ 

trace("Video buffer length: " + nsOutGoing.bufferLength); 
if ( (nsOutGoing.bufferLength == 0) && (streamsHalted == true) ) 
{ 
nsOutGoing.close(); 

// Stop the timer 
bufferCheckTimer.stop(); 

var s:String = Recorder.server+Recorder.fileName+".flv";
videoPlayer.source = s;
videoPlayer.stop();
} 
} 
}

Above code somehow is not working . Its not even loading the swf i guess.
Now, another problem is that, what do I implement in handleOnMetadata and handleOnPlayStatus. Also, is setting up the buffertime is sufficient? How and where do I keep track of the buffer timer?

I am new to Action Script and would appreciate if any one would help in above code in fixing it and implementing the buffer.

Thanks,
Vaibhav