13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with cameras<br />

Displaying camera cont<strong>en</strong>t on scre<strong>en</strong><br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Connecting to a camera can require less code than using the NetConnection and NetStream classes to load a video.<br />

The camera class can also quickly become tricky because with Flash Player, you need a user’s permission to connect to<br />

their camera before you can access it.<br />

The following code demonstrates how you can use the Camera class to connect to a user’s local camera:<br />

var cam:Camera = Camera.getCamera();<br />

var vid:Video = new Video();<br />

vid.attachCamera(cam);<br />

addChild(vid);<br />

Note: The Camera class does not have a constructor method. In order to create a new Camera instance you use the static<br />

Camera.getCamera() method.<br />

Designing your camera application<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> writing an application that connects to a user’s camera, you need to account for the following in your code:<br />

Check if the user has a camera curr<strong>en</strong>tly installed. Handle the case where no camera is available.<br />

For Flash Player only, check if the user has explicitly allowed access to the camera. For security reasons the player<br />

displays the Flash Player Settings dialog which lets the user allow or d<strong>en</strong>y access to their camera. This prev<strong>en</strong>ts Flash<br />

Player from connecting to a user’s camera and broadcasting a video stream without their permission. If a user clicks<br />

allow, your application can connect to the user’s camera. If the user clicks d<strong>en</strong>y, your application will be unable to<br />

access the user’s camera. Your applications should always handle both cases gracefully.<br />

For AIR only, check whether the Camera class is supported for the device profiles supported by your application.<br />

The Camera class is not supported in mobile browsers.<br />

The Camera class is not supported in mobile AIR apps that use the GPU r<strong>en</strong>dering mode.<br />

On iOS, only one camera can be active at a time.<br />

More Help topics<br />

Christophe Co<strong>en</strong>raets: Multi-User Video Tic-Tac-Toe<br />

Mark Doherty: Android Radar app (source)<br />

Connecting to a user’s camera<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The first step wh<strong>en</strong> connecting to a user’s camera is to create a new camera instance by creating a variable of type<br />

Camera and initializing it to the return value of the static Camera.getCamera() method.<br />

Last updated 6/6/2012<br />

521

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!