Motion Detection Webcam with Adobe Flash

An interesting feature and that few people know the Flash Player or Adobe AIR, is that in addition to access features like the webcam user, it can also detect whether there is movement in the camera. This can be useful if you’re implementing a system to stream live and want to save the bandwidth used. For example, the stream will only be published if you have any camera motion.

Flash Player or Adobe AIR, beyond access features such as webcam user can also detect whether there is movement in the camera.

Let’s see an example using Adobe Flash Professional CS5 and Flash Builder 4 (using the Flex framework 4).

Adobe Flash Professional CS5

  • Create a file of type ActionScript 3.0
  • Press F11 to open the library, ask to create a new symbol type “video”:
  • A new window appears, in the name of “cam” and leave the option “Video (ActionScript-controlled)” selected:


  • Drag the component you just created for the stage and the instance name of “cam”, then resize to 320×240.
  • Drag a ProgressBar component’s type library of the User Interface. Name the instance “pbar”.
  • After that you should have something like this:

    Stage ready to start programming

We have our stage ready to start programming ActionScript 3.0. Let’s start with asking the Flash Player to access the webcam and then put the image of the webcam in our component video.
myCam = Camera.getCamera();
Now just to make our movie listen to the event “ActivityEvent” Webcam.
And handlerMotion method, we implement the actions in the ProgressBar.
function handlerMotion(evt:ActivityEvent):void
if( < 10) { trace("muito quieto! =õ("); } else { trace("eba! festa!!! \\o/\\O/\\o/"); } } [/ACTIONSCRIPT3] See example in operation: [SWF],450,400[/SWF] Adobe Flex 4
We will now see an example using Adobe Flex, I’ll grab the camera using component VideoDisplay.

  • Create a project of type web (Flex) or Desktop (AIR).
  • Drag a component of type VideoDisplay and another type ProgressBar to the stage.
  • We have something like this:


Simply implement the ActionScript programming now, is very similar to the way we did in Flash. We will change little in the ActionScript 3.0 code.
protected function application1_creationCompleteHandler(event:FlexEvent):void
pbar.mode = “manual”;
myCam = Camera.getCamera();
var vd:Video = new Video(320,240);
myCam.addEventListener(ActivityEvent.ACTIVITY, handlerMotion);

private function handlerMotion(evt:ActivityEvent):void
if( < 10) { pbar.label = "muito quieto! =õ("; } else { pbar.label = "eba! festa!!! \\o/\\O/\\o/"; } } [/ACTIONSCRIPT3] Now, we only apply the logic to be transmitted or not the stream of the webcam user.



Recommended Books:

Buy Softwares:

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Adobe AIR, Flash, Flex , , ,


  1. Pingback: Anonymous

  2. Pingback: ActionScript Facile |

Leave a Reply