Basic Webcam Handling in Flash CS 3
This post will show you how you can capture a webcam stream in Flash …
But first off all , to make sure the flash settings are correct , check if the same device is pointed out to be the working device as in the image…

Making a new Camera instance and hooking it up with the connected webcam …
var cam:Camera = Camera.getCamera();
Now we will make a new video instance to attach our camera to, and adding this video to the stage (in my example i will add the video instance to a movie clip on the stage)
var video:Video = new Video(320, 240);
//Smoothen your webcam screen
video.smoothing = true;
video.attachCamera(cam);
mcWebcam.addChild(video);
In my example i made it possible to click on my movieclip containing my webcam stream , when done so it captures the webcam stream and includes a little thumbnail of this image in the upper right corner …
To do this i added a event listener to my movieclip that handles the mouse clicking …
//Event Listener
mcWebcam.addEventListener(MouseEvent.MOUSE_DOWN, clickHandler);
The thumbnail is made out of the bitmap data from our webcam stream , so we first captured this bitmap data from the Video instance, which we then transformed to a Bitmap image … And finally added to the thumbnail movieclip on stage …
//Click Handler
function clickHandler(mevt:MouseEvent):void{
//Create new bitmapdata
var bmd:BitmapData = new BitmapData(320,240);
//Attach the webcam video to the bitmapdata
bmd.draw(video);
//Create Bitmap from the bitmapdata
var myBitmap:Bitmap = new Bitmap(bmd);
mcThumb.addChild(myBitmap);
}
Outcome

3 comments so far
Leave a reply
..] Thank you for reading this post. You can now Leave A Comment (0) or Leave A ..]
great site man. thanks for jump starting me on the web cam thing…now i am off to look for a tutorial on getting web cams to talk with eachother.
late.
-maconbot
Great Example!
I was curious about it…
I was trying to copy its BitmapData “Data” to a ByteArray and serialize to save by ExternalInterface on a Javascript call. It works with your example, externalizing the cam data with a bitmapdata, copying it’s content to a bytearray and passing its serialization into javascript to save on a database by ajax.
Thanks guy!