Chapter 6. Mobile Device Hardware Additions

One of the draws of developing for mobile devices is the array of input and output hardware that is built into these small units. Being able to tap into cameras, speakers, and microphones programmatically within our applications is not only desired functionality - but is something that is expected and necessary for many mobile applications. With AIR 3, developers receive a lot more control over these bits of hardware than in previous versions of the mobile runtime.

Camera Position API (Mobile)

Previously available on iOS and TabletOS platforms, the ability to access a front-facing device camera has now been extended to Android.

In order to differentiate between different cameras on a device, we can check the new position property of the flash.media.Camera class. There is also a new flash.media.CameraPosition class which specifies a set of constants that can be used when determining the current camera position.

Note

CameraPosition.FRONT = front-facing device camera
CameraPosition.BACK = back-facing device camera
CameraPosition.UNKNOWN = indeterminate device camera

In the following example, we determine how many cameras are being reported on a device, and subsequently loop through each Camera object, testing against the position property to determine which one is the front-facing device camera. When the desired camera is located, we use that to draw to the screen.

package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; ...

Get What's New in Adobe AIR 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.