0

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
}
Jay
  • 491
  • 1
  • 12
  • 22

1 Answers1

0

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.

null
  • 5,187
  • 1
  • 17
  • 33
  • I tried it but I received this error: `Error #1009: Cannot access a property or method of a null object reference.` Here is my updated code: http://pastebin.com/n1dgwri8 How to fix the error? – Jay Dec 18 '14 at 23:05
  • @Jay I don't see where you instantiate Loader in your code. You don't call loadFilePromise() either. – null Dec 18 '14 at 23:08
  • Added it but it's still not working: http://pastebin.com/CVMqkdZJ Error message `Error: Error #2030: End of file was encountered.` Should that code work or what do I miss? – Jay Dec 18 '14 at 23:23
  • @Jay please actually follow the link I provided that includes the example I mentioned. I'd say that code example should work. – null Dec 18 '14 at 23:30