Connecting to a user's camera

The first step when connecting to a user's camera is to create a new camera instance by creating a variable of type Camera and initializing it to the return value of the static Camera.getCamera() method.

The next step is to create a new video object and attach the Camera object to it.

The third step is to add the video object to the display list. You need to perform steps 2 and 3 because the Camera class does not extend the DisplayObject class so it cannot be added directly to the display list. To display the camera's captured video, you create a new video object and call the attachCamera() method.

The following code shows these three steps:

var cam:Camera = Camera.getCamera();
var vid:Video = new Video();
vid.attachCamera(cam);
addChild(vid);

Note that if a user does not have a camera installed, Flash Player will not display anything.

In real life, you need to perform additional steps for your application. See Verifying that cameras are installed and Detecting permissions for camera access for further information.