This is a blog about Flash & AS by betaruce :-)


June 2007
« May    
  1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

September 24, 2005

WebCam motion detection (simplified code)

Filed under: My Flash Programs, Using Flash — betaruce @ 4:52 pm

Guy Watson has a good article on Webcam motion detection. It makes good use of the new BitmapData methods and blendmode so the code can run pretty fast. His code is really impressive.

However the fla provided in that page is not the most ’simplified’ code and ppl who just started using Flash 8 may have some problems in understanding the code. Therefore I simplified the code a bit and the effect is just similar :)

The code is as follows. You can also download the fla here.

import flash.display.*;
import flash.geom.*;
cam = Camera.get();
now = new BitmapData(cam.width, cam.height);
before = new BitmapData(cam.width, cam.height);
rect = new Rectangle(0, 0, cam.width, cam.height);
pt = new Point(0, 0);
onEnterFrame = function () {
// detect motion if user allow us to access the webcam
if (!cam.muted) {
now.draw(before,new Matrix(),new ColorTransform(),’difference’);

• • •


  1. Thanks man :) Try and keep the number of draw method calls to a minimum, they are pretty expensive.

    Comment by Guy Watson — September 24, 2005 @ 10:14 pm
  2. I thought about mentioning this before but your site is so slooooowww. I was going to post how long it took to download the FLA but it won’t finish downloading….

    You’ve got great content, why don’t you get a better provider?

    Comment by Graeme — September 25, 2005 @ 2:50 am
  3. thx for your comment.

    if you read my post several days b4, i’m already considering changing the provider.

    besides downloading speed, can you view my pages properly?

    Comment by betaruce — September 25, 2005 @ 3:08 am
  4. I didn’t read your post before because most of the time the site doesn’t load for me. Today it seems to be working but crashed my browser with all the camera requests I think. You might want to consider putting a button in your movies for “start” and a small disclaimer saying you will be requesting a connection to a video camera so to connect it up. Just a thought though.. ignore it if you want :)

    Comment by Graeme — September 25, 2005 @ 4:27 am
  5. I think requesting camera won’t crash browser?????

    but anyway thx for your ideas

    I really need to consider changing my webhosting plan.

    Comment by betaruce — September 25, 2005 @ 11:29 am
  6. cool effect, but i dont actualy know how u would manipulate it so you could make it so it would do something if it rolled over a movieclip or something.

    Comment by trig1 — July 12, 2006 @ 1:45 am

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss