user3683186
user3683186

Reputation: 11

Type was not found or was not a compile-time constant: MediaType

I'm trying to take a still photo with flash/as3 and followed the example from Adobe

So the code in my AS file is

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();
        }
    }
}

and on my Timeline I'm calling

 import CameraUIStillImage; 
 var cameraUIStillImage:CameraUIStillImage = new CameraUIStillImage();
 addChild(cameraUIStillImage);

This yields the error

Type was not found or was not a compile-time constant: MediaType

All the solutions to problems like this I've found on Google haven't proved helpful to me. Anyone got an idea what's wrong? :)

Thanks!

Upvotes: 1

Views: 454

Answers (1)

Andrey Popov
Andrey Popov

Reputation: 7520

MediaType.IMAGE is for AIR >= 2.5, so you have to deploy for that target, or it won't work.

Upvotes: 1

Related Questions