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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Working with cameras<br />

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

if (cam == null)<br />

{<br />

trace("User has no cameras installed.");<br />

}<br />

else<br />

{<br />

trace("User has at least 1 camera installed.");<br />

}<br />

Since the Camera class doesn’t ext<strong>en</strong>d the DisplayObject class, it cannot be directly added to the display list using the<br />

addChild() method. In order to display the camera’s captured video, you need to create a new Video object and call<br />

the attachCamera() method on the Video instance.<br />

This snippet shows how you can attach the camera if one exists; if not, the application simply displays nothing:<br />

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

if (cam != null)<br />

{<br />

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

vid.attachCamera(cam);<br />

addChild(vid);<br />

}<br />

Mobile device cameras<br />

The Camera class is not supported in the Flash Player runtime in mobile browsers.<br />

In AIR applications on mobile devices you can access the camera or cameras on the device. On iOS, you can use both<br />

the front- and the back-facing camera, but only one camera output can be displayed at any giv<strong>en</strong> time. (Attaching a<br />

second camera will detach the first.) The front-facing camera is horizontally mirrored on iOS, on Android, it is not.<br />

Detecting permissions for camera access<br />

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

In the AIR application sandbox, the application can access any camera without the user's permission. On Android,<br />

however, the application must specify the Android CAMERA permission in the application descriptor.<br />

Before Flash Player can display a camera’s output, the user must explicitly allow Flash Player to access the camera.<br />

Wh<strong>en</strong> the attachCamera() method gets called Flash Player displays the Flash Player Settings dialog box which<br />

prompts the user to either allow or d<strong>en</strong>y Flash Player access to the camera and microphone. If the user clicks the Allow<br />

button, Flash Player displays the camera’s output in the Video instance on the Stage. If the user clicks the D<strong>en</strong>y button,<br />

Flash Player is unable to connect to the camera and the Video object does not display anything.<br />

If you want to detect whether the user allowed Flash Player access to the camera, you can list<strong>en</strong> for the camera’s status<br />

ev<strong>en</strong>t (StatusEv<strong>en</strong>t.STATUS), as se<strong>en</strong> in the following code:<br />

Last updated 6/6/2012<br />

523

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

Saved successfully!

Ooh no, something went wrong!