The Camera Application and the CameraUI Class

Must Read

Maximizing Your Budget

One of the biggest mistakes that many businesses make is assuming that they have to bid into the number...

Canon PowerShot G12, How I Shoot: A Closer Look at the Camera Settings I Use

Whether it’s isolating my subject with a large aperture or trying to maximize the overall sharpness of a sweeping...

Apply for a Debt Consolidation Loan to Pay Off Your Credit Card Bills

Debt consolidation loan is a key component to help you better manage your debt. The goal is that you...

Disaster Recovery Sauvegarde Restore-y

If you plan to start a business, information systems can be a factor in his plans at a certain...

Avail Hidden Benefits Through Student Debt Consolidation Loan

Are you one of those students who are facing problems due to their multiple debts? This can be the...

Debt Consolidation Loan Versus Remortgage

If, like many people in the U.K. at present, you are not feeling as financially sound as you felt...

You can access the native camera within AIR. Your application needs to have the permission for it. In Flash Professional, select File→AIR Android settings→Permissions→Camera. In Flash Builder, select CAMERA under Mobile Settings→

The class is an addition to the ActionScript language to support the device’s native camera application. It is a subclass of the EventDispatcher class. It is only supported on AIR for mobile applications.

This object allows you to launch the native camera application to take an image or shoot a video while your AIR application moves to the background. The image is stored in the Gallery along with the other images.

To use this class, first you must verify that your device supports access to the camera by checking the CameraUI.isSupported property:

if (CameraUI.isSupported == false) {
trace(“You cannot use the native camera.”);

If camera access is supported, create an instance of the CameraUI class and call its launch function. This function expects one parameter of type MediaType to specify picture or video mode. Choosing a level of compression is not an option at the time of this writing:

var cameraUI:CameraUI = new CameraUI();

The camera application is now active and in the foreground. The AIR application moves to the background.

To receive camera events, set listeners before launching the camera. A Media Event.COMPLETE is dispatched after a picture is taken, an Event.CANCEL if no media is selected, and an ErrorEvent if there is an error in the process:

cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete);
cameraUI.addEventListener(Event.CANCEL, onCancel);
cameraUI.addEventListener(ErrorEvent.ERROR, onError);

Once the event is received, the camera application automatically closes and the AIR application moves back to the foreground.

function onComplete(event:MediaEvent):void {
var promise:MediaPromise = as MediaPromise;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
function onImageLoaded(event:Event):void {
var bitmapData:BitmapData = Bitmap(;
var bitmap:Bitmap = new Bitmap(bitmapData);
var isPortrait:Boolean = (bitmapData.height/bitmapData.width) > 1.0;
var forRatio:int = Math.min(stage.stageHeight, stage.stageWidth);
var ratio:Number;
if (isPortrait) {
ratio = forRatio/bitmapData.width;
} else {
ratio = forRatio/bitmapData.height;
bitmap.width = bitmapData.width * ratio;
bitmap.height = bitmapData.height * ratio;
if (!isPortrait) {
bitmap.y = stage.stageHeight;
bitmap.rotation = -90;

Uploading to a Remote Server

Images can be uploaded to a remote server if you have access to one. You need the Internet permission to add this functionality:

<uses-permission android:name=”android.permission.INTERNET” />

This process is identical to what you would do in a desktop application:

import flash.filesystem.File;
var request:URLRequest = new URLRequest(“server url”);
request.method = URLRequestMethod.POST;
var uploadFile:File = new File(promise.file.url);


Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place at the...

More Articles Like This