2 Replies Latest reply on Jun 28, 2011 8:58 AM by MarcosMonsao

    How to get a picture of iPhone Gallery with Flex 4.5?




      I would like know how can to get a picture of iPhone Galery and insert in a Component Image on Flex 4.5.



        • 2. Re: How to get a picture of iPhone Gallery with Flex 4.5?
          MarcosMonsao Level 1

          <?xml version="1.0" encoding="utf-8"?>

          <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

          xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView"





          import flash.display.Loader;

          import flash.events.IOErrorEvent;

          import flash.events.MediaEvent;


          private var mediaCamera:CameraRoll;

          private var imageLoader:Loader;


          protected function openGalery(event:MouseEvent):void{

          if (mediaCamera != null){





          protected function init():void{

          if (CameraRoll.supportsBrowseForImage){


          mediaCamera = new CameraRoll();

          mediaCamera.addEventListener( MediaEvent.SELECT, imageSelected );

          mediaCamera.addEventListener( Event.CANCEL, browseCanceled );

          mediaCamera.addEventListener( ErrorEvent.ERROR, browseErro );





          public function browseErro( event:ErrorEvent ):void


          lblMsg.text = lblMsg.text+" -  ERRO browse";



          public function browseCanceled( event:Event ):void


          lblMsg.text = lblMsg.text+" -  browse Cancel";



          public function imageSelected( event:MediaEvent ):void


          var imagePromise:MediaPromise = event.data as MediaPromise;

          imageLoader = new Loader();

          imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );

          imageLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );

          imageLoader.loadFilePromise( imagePromise );




          public function imageLoaded( event:Event ):void


          var bitmapData:BitmapData = Bitmap(event.target.content).bitmapData;

          var bitmap:Bitmap = new Bitmap(bitmapData);

                   imgPhoto.source = bitmap;




          public function imageLoadFailed( event:Event ):void


          lblMsg.text = lblMsg.text+" -  ERRO Load ";







          <!-- Place non-visual elements (e.g., services, value objects) here -->


          <s:Button id="btnGalery" left="123" right="123" bottom="18" label="Galeria"


          <s:Image id="imgPhoto" left="13" right="7" top="6" bottom="107"/>

          <s:Label id="lblMsg" left="10" right="10" bottom="69" height="30"/>