RSS

iPhone image library Access with ActionScript 3 (flash.media.CameraRoll)

27 May
package flash.media.examples
{
        import flash.media.CameraRoll;
        import flash.media.MediaPromise;
        import flash.media.MediaType;
        import flash.events.MediaEvent;
        import flash.events.Event;
        import flash.display.Loader;
        import flash.display.Sprite;
        import flash.events.IOErrorEvent;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;

        public class CameraRollTest extends Sprite{
            private var mediaSource:CameraRoll = new CameraRoll();

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

                if( CameraRoll.supportsBrowseForImage )
                {
                    log( "Browsing for image..." );
                    mediaSource.addEventListener( MediaEvent.SELECT, imageSelected );
                    mediaSource.addEventListener( Event.CANCEL, browseCanceled );

                    mediaSource.browseForImage();
                }
                else
                {
                    log( "Browsing in camera roll is not supported.");
                }
            }

            private var imageLoader:Loader;
            private function imageSelected( event:MediaEvent ):void
            {
                log( "Image selected..." );

                var imagePromise:MediaPromise = event.data;

                imageLoader = new Loader();
                if( imagePromise.isAsync )
                {
                    log( "Asynchronous media promise." );
                    imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, imageLoaded );
                    imageLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, imageLoadFailed );
                    imageLoader.loadFilePromise( imagePromise );
                }
                else
                {
                    log( "Synchronous media promise." );
                    imageLoader.loadFilePromise( imagePromise );
                    this.addChild( imageLoader );
                }
            }

            private function browseCanceled( event:Event ):void
            {
                log( "Image browse canceled." );
            }

            private function imageLoaded( event:Event ):void
            {
                log( "Image loaded asynchronously." );
                this.addChild( imageLoader );
            }

            private function imageLoadFailed( event:Event ):void
            {
                log( "Image load failed." );
            }

            private function log( text:String ):void
            {
                trace( text );
            }

        }

    }
Original link
Advertisements
 

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: