The Camera Application and the CameraUI Class

Must Read

How To Shop On Black Friday

The term Black Friday was coined by the Philadelphia Police Department in the year 1966. It was a day...

Homeowners Refinance Mortgages To Consolidate Credit Card Debt and Save Money

If you are a homeowner you have likely survived the recent economic turmoil. The real estate market has been...

Techniques for business blogs: Blogging Techniques Unreal business, you should use daily

Let law 's get into it. Are we going? Let 's on corporate blogging techniques that work...

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);



Please enter your comment!
Please enter your name here

Latest News

Top 10 Provinces of Thailand Not to be missed for Travel

10 SuratthaniThe source of the proverbial Chaiya salted egg. Surat Thani is a province with many attractions,...

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits, even though it will have...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

More Articles Like This