Capturing image from webcam and loading to Flash

Hi,

I’m trying to have a webcam option in my flash that would allows the user (if they have a webcam) to take a picture of themselves and show this picture in flash.

So far I’ve only been able to get the camera part working, that is the webcam feed is showing. How do I go about capturing the image when a user presses the button and then load that up in the flash?


import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.external.ExternalInterface;

var bandwidth:int = 0; // Specifies the maximum amount of bandwidth that the current outgoing video feed can use, in bytes per second. To specify that Flash Player video can use as much bandwidth as needed to maintain the value of quality , pass 0 for bandwidth . The default value is 16384.
var quality:int = 100; // this value is 0-100 with 1 being the lowest quality. Pass 0 if you want the quality to vary to keep better framerates
var camera:Camera = Camera.getCamera();
camera.setQuality(bandwidth, quality);
camera.setMode(320,240,30,false); // setMode(videoWidth, videoHeight, video fps, favor area)
var video:Video = new Video();
video.attachCamera(camera);
addChild(video);

var screenS:BitmapData = new BitmapData(video.width, video.height, true, 0xff0000);

btnTake.addEventListener(MouseEvent.MOUSE_DOWN, capture);

function capture(evt:MouseEvent):void{
    screenS.draw(video);

	var pixels:Array = new Array();
	var w:Number = screenS.width;
	var h:Number = screenS.height;
	for (var a=0; a<=w; a++) {
		for (var b=0; b<=h; b++) {
			var tmp = screenS.getPixel(a,b).toString(16);
			pixels.push(tmp);
		}
	}

How can I convert the pixels array so that it is displayed as an image in Flash?