Hi,
My students and I have not been able to make an AIR app that can take a picture using the devices camera and then add the image to the display list. We are able to open the devices camera and of course take a picture, but that's it.
We've been using these two tutorials/examples:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/media/CameraUI.html
and
http://tv.adobe.com/watch/adc-presents/input-for-mobile-devices-camera /
I've uploaded our project: http://www.dayvid.com/professor/camera.zip
Can someone help us out?
Thanks!
Below is the main document class:
package {
import flash.desktop.NativeApplication;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.ErrorEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.MediaEvent;
import flash.media.CameraUI;
import flash.media.MediaPromise;
import flash.media.MediaType;
import flash.events.MouseEvent;
public class Main extends MovieClip{
private var deviceCameraApp:CameraUI = new CameraUI();
private var imageLoader:Loader;
public function Main()
{
this.stage.align = StageAlign.TOP_LEFT;
this.stage.scaleMode = StageScaleMode.NO_SCALE;
camera_btn.addEventListener(MouseEvent.CLICK, cameraBtnClicked);
}
private function cameraBtnClicked(event:MouseEvent):void
{
if( CameraUI.isSupported )
{
result_txt.text = "Initializing camera...";
deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
deviceCameraApp.launch( MediaType.IMAGE );
}
else
{
result_txt.text = "Camera interface is not supported.";
}
}
private function imageCaptured( event:MediaEvent ):void
{
result_txt.text = "Media captured...";
var imagePromise:MediaPromise = event.data;
if( imagePromise.isAsync )
{
result_txt.text = "Asynchronous media promise.";
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );
imageLoader.loadFilePromise( imagePromise );
}
else
{
result_txt.text = "Synchronous media promise.";
imageLoader.loadFilePromise( imagePromise );
showMedia( imageLoader );
}
}
private function captureCanceled( event:Event ):void
{
result_txt.text = "Media capture canceled.";
NativeApplication.nativeApplication.exit();
}
private function asyncImageLoaded( event:Event ):void
{
result_txt.text = "Media loaded in memory.";
showMedia( imageLoader );
}
private function showMedia( loader:Loader ):void
{
this.addChild( loader );
}
private function cameraError( error:ErrorEvent ):void
{
result_txt.text = "Error:" + error.text;
NativeApplication.nativeApplication.exit();
}
}
}