4 Replies Latest reply: Jun 2, 2012 6:13 AM by kglad RSS

    how to capture a photo on iOS?

    royhermann

      I have built this simple code that calls the iphones camera interface once the user taps the button "TFM" :

       

      Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

       

       

       

      TFM.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler); //when you tap on TFM

       

       

      function fl_TapHandler(event:TouchEvent):void

      {

       

            var cameraUI:CameraUI = new CameraUI();

           cameraUI.launch( MediaType.IMAGE );

      }

       

      From what i understand i add an event listener that is trigerred once the picture is complete, and in this event listener i create a function which saves the captured photo into the users camera roll :

       

       

      cameraUI.addEventListener( MediaEvent.COMPLETE, onComplete);

       

      What do i code for the "onComplete" function inorder to save the photo on the users phone (in camera roll) ?

       

       

       

       

      Thanks!

        • 1. Re: how to capture a photo on iOS?
          kglad CommunityMVP

          :

           

           

           

          Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

           

           

           

          TFM.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler); //when you tap on TFM

           

           

          function fl_TapHandler(event:TouchEvent):void

          {

           

                var cameraUI:CameraUI = new CameraUI();

               cameraUI.launch( MediaType.IMAGE );

          }

           

           

           

           

          cameraUI.addEventListener( MediaEvent.COMPLETE, onComplete);
           function onComplete( e:MediaEvent ):void { 
          var imagePromise:MediaPromise = e.data; 
          if( imagePromise.isAsync ) {
          var imageLoader:Loader = new Loader();
          imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
          imageLoader.loadFilePromise( imagePromise );
          } else {
          imageLoader.loadFilePromise( imagePromise );
          showMedia( imageLoader );
          }

          function asyncImageLoaded( e:Event ):void {
          showMedia( e.target.loader );
          }
          function showMedia( loader:Loader ):void {
          this.addChild( loader );
          }
          • 2. Re: how to capture a photo on iOS?
            royhermann Community Member

            first, thanks kglad for the response.

            however i literally copy pasted it and published the new app, however it just takesa picture and goes back to the main app's screen without saving the photo in the camera roll.

            This is the whole code including yours, is there any reason for this not be working or is it possibly missing something?

             

             

             

            Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

            TFM.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler);

             

             

            function  fl_TapHandler(event:TouchEvent):void

            {

             

             

            var cameraUI:CameraUI = new CameraUI();

            cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete);

            cameraUI.launch(MediaType.IMAGE);

             

            function onComplete( e:MediaEvent ):void

            {

                      var imagePromise:MediaPromise = e.data; 

                                          if( imagePromise.isAsync )

                                          {

                                                    var imageLoader:Loader = new Loader();

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

                                                    imageLoader.loadFilePromise( imagePromise );

                                          }

                                          else

                                          {

                                           imageLoader.loadFilePromise( imagePromise );

                                          showMedia( imageLoader );

                                          }

             

             

            function asyncImageLoaded( e:Event ):void

                      {

                      showMedia( e.target.loader );

                      }

            function showMedia( loader:Loader ):void

                      {

                      this.addChild( loader );

                      }

            • 3. Re: how to capture a photo on iOS?
              royhermann Community Member

              also just for clarifcation, i am using flash professional not flash builder or anything...and all this code is written in a seperate frame in the 'actions' layer.

              • 4. Re: how to capture a photo on iOS?
                kglad CommunityMVP

                you use the cameraui class if you want to add a bitmap of the just snapped image to your flash app.

                 

                if you want to save an bitmapdata object from flash to the cameraroll, you should be using the cameraroll class.