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 />

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

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<br />

does not ext<strong>en</strong>d the DisplayObject class so it cannot be added directly to the display list. To display the camera’s<br />

captured video, you create a new video object and call the attachCamera() method.<br />

The following code shows these three steps:<br />

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

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

vid.attachCamera(cam);<br />

addChild(vid);<br />

Note that if a user does not have a camera installed, the application does not display anything.<br />

In real life, you need to perform additional steps for your application. See “Verifying that cameras are installed” on<br />

page 522 and “Detecting permissions for camera access” on page 523 for further information.<br />

More Help topics<br />

Lee Brimelow: How to access the camera on Android devices<br />

Verifying that cameras are installed<br />

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

Before you attempt to use any methods or properties on a camera instance, you’ll want to verify that the user has a<br />

camera installed. There are two ways to check whether the user has a camera installed:<br />

Check the static Camera.names property which contains an array of camera names which are available. Typically<br />

this array will have one or fewer strings, as most users will not likely have more than one camera installed at a time.<br />

The following code demonstrates how you could check the Camera.names property to see if the user has any<br />

available cameras:<br />

if (Camera.names.l<strong>en</strong>gth > 0)<br />

{<br />

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

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

}<br />

else<br />

{<br />

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

}<br />

Check the return value of the static Camera.getCamera() method. If no cameras are available or installed, this<br />

method returns null, otherwise it returns a refer<strong>en</strong>ce to a Camera object. The following code demonstrates how<br />

you could check the Camera.getCamera() method to see if the user has any available cameras:<br />

Last updated 6/6/2012<br />

522

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

Saved successfully!

Ooh no, something went wrong!