RSS

IPhone camera Access with ActionScript 3(flash.media.CameraUI)

27 May
package  {
 import flash.desktop.NativeApplication;
 import flash.display.Loader;
 import flash.display.MovieClip;
 import flash.display.StageAlign;
 import flash.display.StageScaleMode;
 import flash.events.ErrorEvent;
 import flash.events.Event;
 import flash.events.IOErrorEvent;
 import flash.events.MediaEvent;
 import flash.media.CameraUI;
 import flash.media.MediaPromise;
 import flash.media.MediaType;

     public class CameraUIStillImage extends MovieClip{

          private var deviceCameraApp:CameraUI = new CameraUI();
          private var imageLoader:Loader; 

          public function CameraUIStillImage() {
               this.stage.align = StageAlign.TOP_LEFT;
               this.stage.scaleMode = StageScaleMode.NO_SCALE;

               if( CameraUI.isSupported )
               {
                trace( "Initializing camera..." );

                deviceCameraApp.addEventListener( MediaEvent.COMPLETE, imageCaptured );
                deviceCameraApp.addEventListener( Event.CANCEL, captureCanceled );
                deviceCameraApp.addEventListener( ErrorEvent.ERROR, cameraError );
                deviceCameraApp.launch( MediaType.IMAGE );
               }
               else
               {
                trace( "Camera interface is not supported.");
               }
          }

          private function imageCaptured( event:MediaEvent ):void
          {
               trace( "Media captured..." );

               var imagePromise:MediaPromise = event.data;

               if( imagePromise.isAsync )
               {
                trace( "Asynchronous media promise." );
                imageLoader = new Loader();
                imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
                imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );

                imageLoader.loadFilePromise( imagePromise );
               }
               else
               {
                trace( "Synchronous media promise." );
                imageLoader.loadFilePromise( imagePromise );
                showMedia( imageLoader );
               }
          }

          private function captureCanceled( event:Event ):void
          {
               trace( "Media capture canceled." );
               NativeApplication.nativeApplication.exit();
          }

          private function asyncImageLoaded( event:Event ):void
          {
               trace( "Media loaded in memory." );
               showMedia( imageLoader );
          }

          private function showMedia( loader:Loader ):void
          {
               this.addChild( loader );
          }

          private function cameraError( error:ErrorEvent ):void
          {
               trace( "Error:" + error.text );
               NativeApplication.nativeApplication.exit();
          }
     }
}
Original link 
Advertisements
 

6 responses to “IPhone camera Access with ActionScript 3(flash.media.CameraUI)

  1. Kingoman

    August 4, 2011 at 4:00 pm

    I’ve tried the script on iPad and it works fine. But if the iPad is rotated left (default landscape), the captured image is upside down. How do I avoid that?

     
    • flashpri

      August 5, 2011 at 10:40 pm

      Rotate your image in 90 degree. >> my_mc.rotation = 90

       
  2. Kingoman

    August 10, 2011 at 12:15 am

    I’ve tried this without any luck. Same problem.

    import flash.display.StageOrientation;

    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;

    var startOrientation:String = stage.orientation;

    if (startOrientation == “default”)
    {
    stage.setOrientation(StageOrientation.ROTATED_RIGHT);
    }
    if (startOrientation == “upsideDown”)
    {
    stage.setOrientation(StageOrientation.ROTATED_LEFT);
    }

    stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener);
    function orientationChangeListener(e:StageOrientationEvent)
    {
    if (e.afterOrientation == “default” || e.afterOrientation == “upsideDown”)
    {
    e.preventDefault();
    }
    }

     
  3. Ron Kuipers (@kuupke)

    August 19, 2011 at 8:20 pm

    I’m trying this code but get the following error:

    Line 39 1046: Type was not found or was not a compile-time constant: MediaEvent.

    What am i doing wrong?

     
    • flashpri

      August 20, 2011 at 11:13 pm

      Change your publish settings.

      Click on File menu – Publish Settings –

      Change Player >> Air for iOS

      Note : I am using adobe flash CS5.5

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: