Packageflash.media
Classpublic class CameraRoll
InheritanceCameraRoll Inheritance EventDispatcher Inheritance Object

Language version: ActionScript 3.0
Runtime version: AIR 2

The CameraRoll class allows you to access image data in the system media library or "camera roll."

AIR profile support: This feature is supported on mobile devices, but it is not supported on desktop operating systems or AIR for TV devices. See AIR Profile Support for more information regarding API support across multiple profiles.

The CameraRoll.addBitmapData() method adds an image to the device's dedicated media library. To check at run time whether your application supports the CameraRoll.addBitmapData() method, check the CameraRoll.supportsAddBitmapData property.

The CameraRoll.browseForImage() method opens an image-choosing dialog that allows a user to choose an image in the media library. When the user selects an image, the CameraRoll object dispatches a select event. Use the MediaEvent object dispatched for this event to access the chosen image. To check at run time whether your application supports the CameraRoll.browseForImage() method, check the CameraRoll.supportsBrowseForImage property.



Public Properties
 PropertyDefined by
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  permissionStatus : String
[static][read-only] Determine whether the application has been granted the permission to access camera roll.
CameraRoll
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  supportsAddBitmapData : Boolean
[static][read-only] Whether the CameraRoll.addBitmapData() method is supported.
CameraRoll
  supportsBrowseForImage : Boolean
[static][read-only] Reports whether the CameraRoll.browseForImage() method is supported.
CameraRoll
Public Methods
 MethodDefined by
  
Creates a CameraRoll object.
CameraRoll
  
Adds an image to the device camera roll.
CameraRoll
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
  
Opens an image browser dialog to allow the user to select an existing image from the device camera roll.
CameraRoll
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
  
Requests permission to access system media library or "camera roll".
CameraRoll
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 EventSummaryDefined by
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
   Dispatched when a user cancels a browse-for-image operation without selecting an image.CameraRoll
   Signals that an addBitmapData() operation completed successfully.CameraRoll
 Inherited [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
   The error event is dispatched when an error occurs.CameraRoll
   Dispatched when the application requests permission to access camera roll.CameraRoll
   Dispatched when a user selects an image from the device media library.CameraRoll
Property detail
permissionStatusproperty
permissionStatus:String  [read-only]

Language version: ActionScript 3.0
Runtime version: AIR 24.0

Determine whether the application has been granted the permission to access camera roll.

Implementation
    public static function get permissionStatus():String

See also

supportsAddBitmapDataproperty 
supportsAddBitmapData:Boolean  [read-only]

Language version: ActionScript 3.0
Runtime version: AIR 2

Whether the CameraRoll.addBitmapData() method is supported. Currently, the feature is only supported in AIR applications on mobile devices.

Implementation
    public static function get supportsAddBitmapData():Boolean
supportsBrowseForImageproperty 
supportsBrowseForImage:Boolean  [read-only]

Language version: ActionScript 3.0
Runtime version: AIR 2.5

Reports whether the CameraRoll.browseForImage() method is supported. Currently, the feature is only supported in AIR applications on mobile devices.

Implementation
    public static function get supportsBrowseForImage():Boolean
Constructor detail
CameraRoll()constructor
public function CameraRoll()

Language version: ActionScript 3.0
Runtime version: AIR 2

Creates a CameraRoll object.

There is only a single media library supported by ActionScript. All CameraRoll objects save to the same image repository.

Method detail
addBitmapData()method
public function addBitmapData(bitmapData:BitmapData):void

Language version: ActionScript 3.0
Runtime version: AIR 2

Adds an image to the device camera roll.

To check at run time whether your application supports the CameraRoll.addBitmapData() method, check the CameraRoll.supportsAddBitmapData property.

Parameters
bitmapData:BitmapData — a BitmapData object containing the image to send to the camera roll.

Throws
PermissionError — The application does not have permission to use camera.
browseForImage()method 
public function browseForImage(value:CameraRollBrowseOptions = null):void

Language version: ActionScript 3.0
Runtime version: AIR 2.5

Opens an image browser dialog to allow the user to select an existing image from the device camera roll.

When the user selects an image, this CameraRoll instance dispatches a select event containing a MediaEvent object. Use the data property of the MediaEvent object to load the image. The data property is a MediaPromise object, which you can load using the loadFilePromise() method of the Loader class. Note that the MediaPromise object contains a valid file object on some platforms (Blackberry Tablet OS), but not on others (iOS and Android). When you use the loadFilePromise() method, the image is loaded properly on all platforms. To access the raw data from the media object, you can open the data source provided by the media promise and read the data using the methods from the IDataInput interface.

To check at run time whether your application supports the CameraRoll.browseForImage() method, check the CameraRoll.supportsBrowseForImage property.

On iOS (and only on the iPad) you can request a specific size for the image browser dialog. You can also specify an area of the screen that you don't want the image browser dialog to cover. This request works only on the iPad, because on that device the image browser does not occupy the entire screen.

To request size and placement options for the image browser (for iPad), pass a CameraRollBrowseOptions object to browseForImage(). With no parameters, this method positions the dialog in the display's top-left corner, using system defaults for the dialog's dimensions.

Parameters
value:CameraRollBrowseOptions (default = null) — A CameraRollBrowseOptions object that you can use to specify options for displaying the image roll dialog. This parameter is optional.

Events
select:MediaEvent — Dispatched when the user chooses an image.
 
cancel:Event — Dispatched when a user cancels the browse operation.
 
error:ErrorEvent — Dispatched if the default image browser application is already in use.
 
error:ErrorEvent — Dispatched if the AIR application is in the background when it calls this function.

Throws
PermissionError — The application does not have permission to use camera.

See also


Example
package flash.media.examples
{
    	import flash.media.CameraRoll;
		import flash.media.MediaPromise;
		import flash.media.MediaType;
		import flash.events.MediaEvent;
		import flash.events.Event;
		import flash.display.Loader;
		import flash.display.Sprite;
		import flash.events.IOErrorEvent;
		import flash.display.StageAlign;
		import flash.display.StageScaleMode;
		
		public class CameraRollTest extends Sprite{
			private var mediaSource:CameraRoll = new CameraRoll();
			
			public function CameraRollTest() {
				this.stage.align = StageAlign.TOP_LEFT;
				this.stage.scaleMode = StageScaleMode.NO_SCALE;
				
				if( CameraRoll.supportsBrowseForImage )
				{
					log( "Browsing for image..." );
					mediaSource.addEventListener( MediaEvent.SELECT, imageSelected );
					mediaSource.addEventListener( Event.CANCEL, browseCanceled );
					
					mediaSource.browseForImage();
				}
				else
				{
					log( "Browsing in camera roll is not supported.");
				}
			}
			
			private var imageLoader:Loader; 
			private function imageSelected( event:MediaEvent ):void
			{
				log( "Image selected..." );
				
				var imagePromise:MediaPromise = event.data;
				
				imageLoader = new Loader();
				if( imagePromise.isAsync )
				{
					log( "Asynchronous media promise." );
					imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );
					imageLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );
					imageLoader.loadFilePromise( imagePromise );
				}
				else
				{
					log( "Synchronous media promise." );
					imageLoader.loadFilePromise( imagePromise );
					this.addChild( imageLoader );
				}
			}
			
			private function browseCanceled( event:Event ):void
			{
				log( "Image browse canceled." );
			}
			
			private function imageLoaded( event:Event ):void
			{
				log( "Image loaded asynchronously." );
				this.addChild( imageLoader );
			}
			
			private function imageLoadFailed( event:Event ):void
			{
				log( "Image load failed." );
			}
			
			private function log( text:String ):void
			{
				trace( text );
			}
			
		}
		
	}

requestPermission()method 
public function requestPermission():void

Language version: ActionScript 3.0
Runtime version: AIR 24.0

Requests permission to access system media library or "camera roll".


Events
PermissionStatus:PermissionEvent — dispatched when the requested permission is granted/denied by the user.
Event detail
cancelevent 
Event object type: flash.events.Event
Event.type property = flash.events.Event.CANCEL

Language version: ActionScript 3.0
Runtime version: AIR 2.5

Dispatched when a user cancels a browse-for-image operation without selecting an image.

The Event.CANCEL constant defines the value of the type property of a cancel event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetA reference to the object on which the operation is canceled.
completeevent  
Event object type: flash.events.Event
Event.type property = flash.events.Event.COMPLETE

Language version: ActionScript 3.0
Runtime version: AIR 2

Signals that an addBitmapData() operation completed successfully.

The Event.COMPLETE constant defines the value of the type property of a complete event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe network object that has completed loading.
errorevent  
Event object type: flash.events.ErrorEvent
ErrorEvent.type property = flash.events.ErrorEvent.ERROR

Language version: ActionScript 3.0
Runtime version: AIR 2

The error event is dispatched when an error occurs.

Sources of errors include:

Defines the value of the type property of an error event object.

This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object experiencing a network operation failure.
textText to be displayed as an error message.
permissionStatusevent  
Event object type: flash.events.PermissionEvent

Language version: ActionScript 3.0
Runtime version: AIR 24.0

Dispatched when the application requests permission to access camera roll. Check the value of status property to determine whether the permission was granted or denied

See also

selectevent  
Event object type: flash.events.MediaEvent
MediaEvent.type property = flash.events.MediaEvent.SELECT

Language version: ActionScript 3.0
Runtime version: AIR 2.5

Dispatched when a user selects an image from the device media library.

The MediaEvent object dispatched for this event provides access to the chosen media.

A constant for the select MediaEvent.

Defines the value of the type property of a MediaEvent event object. This event has the following properties:

PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
dataThe MediaPromise object of the available media instance.