Add bitmap to stage from CameraRoll loaded image

333 Views Asked by At

I need to use the code below to load an image from the CameraRoll with Adobe Air on iOS 8. (it will also be used to read the EXIF data from the loaded image) I would like to add the bitmap via addChild() to the stage as soon as the onMediaLoadedCameraRoll function gets triggered. How to do that?

var loaderCameraRoll:Loader 
var deviceCameraRoll:CameraRoll

var dataSourceCameraRoll:IDataInput;
var mediaPromiseCameraRoll:MediaPromise;

function loadImageFromCameraRoll(e:Event=null):void {
deviceCameraRoll = new CameraRoll();
deviceCameraRoll.addEventListener(MediaEvent.SELECT, onSelectCameraRoll);
deviceCameraRoll.browseForImage();
}

function onSelectCameraRoll(event:MediaEvent):void {
        mediaPromiseCameraRoll = event.data;
        dataSourceCameraRoll = mediaPromiseCameraRoll.open();
        var eventSource:IEventDispatcher = dataSourceCameraRoll as IEventDispatcher;           
        eventSource.addEventListener( Event.COMPLETE, onMediaLoadedCameraRoll );        
}

function onMediaLoadedCameraRoll(event:Event):void {
// display loaded image
}
1

There are 1 best solutions below

4
On

The documentation says this about the matter:

The data property is a MediaPromise object, which you can load using the loadFilePromise() method of the Loader class.

This is followed by an example that does exactly that:

                var imagePromise:MediaPromise = event.data;
                    imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );
                    imageLoader.loadFilePromise( imagePromise );

As seen in the example code, you should always add the listeners for a Loader to its contentLoaderInfo property.