Camera is a simple extension to give developers access to the camera flash on iOS and Android.

Some features:

  • Allows control of the camera’s flash
  • Compatible with most Android devices and iOS 4+ devices which include a flash
  • Sample project code and ASDocs reference

Sample

package
{
	import com.distriqt.extension.camera.Camera;
	import com.distriqt.extension.camera.CameraParameters;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;

	/**
	 * This is the main implementation class of the TestCamera application
	 *
	 * The application demonstrates the usage of the Camera Native Extension
	 *
	 * @author Michael Archbold (ma@distriqt.com)
	 *
	 */
	public class TestCamera extends Sprite
	{

		private var _messageField	: TextField;

		private var _mode			: String = CameraParameters.FLASH_MODE_OFF;

		public function TestCamera()
		{
			super();

			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;

			var tf:TextFormat = new TextFormat();
			tf.size = 24;
			_messageField = new TextField();
			_messageField.defaultTextFormat = tf;
			_messageField.width = 480;
			_messageField.height = 800;
			_messageField.selectable = false;
			addChild( _messageField );
			_messageField.text = "Press to toggle the flash\n";

			try
			{
				message( "Camera.isSupported::"+Camera.isSupported );
				message( "Camera.isFlashSupported::"+Camera.isFlashSupported );

				Camera.init( "123412341234" );

				message( Camera.instance.version );
			}
			catch (e:Error)
			{
				message( "ERROR: "+e.message );
			}

			stage.addEventListener( MouseEvent.CLICK, mouseClickHandler, false, 0, true );

			// Just demonstrating initialising and releasing access to the camera
			stage.addEventListener( Event.ACTIVATE,   stage_activateHandler, false, 0, true );
			stage.addEventListener( Event.DEACTIVATE, stage_deactivateHandler, false, 0, true );
		}

		////////////////////////////////////////////////////////
		//	FUNCTIONALITY
		//

		private function message( str:String ):void
		{
			trace( str );
			_messageField.appendText(str+"\n");
		}

		private function init():void
		{
			try
			{
				//	Call this to initialise the camera extension
				Camera.instance.initialise();
			}
			catch (e:Error)
			{
				message( "ERROR: "+e.message );
			}
		}

		private function destroy():void
		{
			try
			{
				//	Call this to release the camera
				Camera.instance.release();
			}
			catch (e:Error)
			{
				message( "ERROR: "+e.message );
			}
		}

		private function toggleFlash():void
		{
			if (_mode == CameraParameters.FLASH_MODE_TORCH)
			{
				_mode = CameraParameters.FLASH_MODE_OFF;
			}
			else
			{
				_mode = CameraParameters.FLASH_MODE_TORCH;
			}

			try
			{
				Camera.instance.setFlashMode( _mode );
				message( "MODE:"+_mode );
			}
			catch (e:Error)
			{
				message( "ERROR: "+e.message );
			}
		}

		////////////////////////////////////////////////////////
		//	EVENT HANDLERS
		//

		private function mouseClickHandler( event:MouseEvent ):void
		{
			toggleFlash();
		}

		private function stage_activateHandler( event:Event ):void
		{
			init();
		}

		private function stage_deactivateHandler( event:Event ):void
		{
			destroy();
		}

	}
}
Air Native Extension, Android, iOS . URL.