O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.4. Capturing and Displaying Video from a Web Cam

Problem

You want to display the video from a user’s web cam within a Flash movie, or you want to capture the data in order to publish it to a FlashCom application. (See Recipe 14.9.)

Solution

Use the Camera.get( ) method.

Discussion

The Camera.get( ) method returns a stream of (video-only) data from the camera attached to the user’s computer. For example:

myCam_cam = Camera.get(  );

If there are multiple cameras, Flash defaults to the camera that is selected under the Camera tab of the Player Settings dialog box. Flash also assigns each recognized camera an index, starting from 0 and incrementing by 1. For example, if there are three cameras attached to the computer, Flash identifies them by the indexes 0, 1, and 2. You can pass the index to the Camera.get( ) method to open a data stream from that camera:

// Open a stream from the second camera.
myCam_cam = Camera.get(1);

In practice, developers ordinarily use one of two strategies:

  • Allow the user to select a camera before opening the camera stream.

  • Open the camera stream to the default camera, and then allow the user to choose a different camera.

You can allow a user to choose a camera in at least two ways:

  • Open the Player Settings dialog box to the Camera tab using the following code:

    System.showSettings(3);

    However, this technique is intrusive because it confronts the user with the Player Settings dialog box. Therefore, you should provide a button to open the Player Settings dialog box, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required