Skip to main content
Known Participant
August 17, 2011
Answered

Access to the Camera Roll AS3 Flash CS5.5

  • August 17, 2011
  • 2 replies
  • 8494 views

Hello

I'm looking and looking but can´t find nothing about access the camera roll and camera to take a picture to my App, Does anybody have any code to do that?,

Not Class please, Just AS3

Or perhaps prefer to point me to a URL?

Thanks

This topic has been closed for replies.
Correct answer Colin Holgate

There are a few differences between the two needs. For fun, I just made a screen recording of me converting the Help example for CameraRoll into a timeline version! Here's the screen recording:

http://xfiles.funnygarbage.com/~colinholgate/video/camerrolltimeline.mov

and here's the finale code, which includes the various error trapping, and Android support too:

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;

var mediaSource:CameraRoll = new CameraRoll();

CameraRollTest();

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.");

}

}

var imageLoader:Loader;

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

}

}

function browseCanceled( event:Event ):void {

log( "Image browse canceled." );

}

function imageLoaded( event:Event ):void {

log( "Image loaded asynchronously." );

this.addChild( imageLoader );

}

function imageLoadFailed( event:Event ):void {

log( "Image load failed." );

}

function log( text:String ):void {

trace( text );

}

2 replies

August 17, 2011

Thanks Colin for simplyfing that, I get dizzy when I see the class explanation of the code, its nice to see a timeline version.

I too am interested in how that code can be modified to pull an image from the camera roll, although if the code evokes the device camera cant the user simply switch to the native device option of selecting from the album.

Colin Holgate
Colin HolgateCorrect answer
Inspiring
August 17, 2011

There are a few differences between the two needs. For fun, I just made a screen recording of me converting the Help example for CameraRoll into a timeline version! Here's the screen recording:

http://xfiles.funnygarbage.com/~colinholgate/video/camerrolltimeline.mov

and here's the finale code, which includes the various error trapping, and Android support too:

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;

var mediaSource:CameraRoll = new CameraRoll();

CameraRollTest();

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.");

}

}

var imageLoader:Loader;

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

}

}

function browseCanceled( event:Event ):void {

log( "Image browse canceled." );

}

function imageLoaded( event:Event ):void {

log( "Image loaded asynchronously." );

this.addChild( imageLoader );

}

function imageLoadFailed( event:Event ):void {

log( "Image load failed." );

}

function log( text:String ):void {

trace( text );

}

Known Participant
August 18, 2011

Thank you! ...

Works great ...

One question, I'm using your code without

this.stage.align = StageAlign.TOP_LEFT;

this.stage.scaleMode = StageScaleMode.NO_SCALE;

Why is this necessary?

Do you know how can I do to the user can zoom and adjust the size of the picture?

Thank you again ... your code is more simple to read and implement!

Pahup
Adobe Employee
Adobe Employee
August 17, 2011
Known Participant
August 17, 2011

Thank you, but I dont know so much about Classes ... How suppose That I should I call this Functions? ... just name them? or need parameters?

Known Participant
August 17, 2011

Anybody has used the Class of the ADOBE example or get an image from the camera roll?

I've defined a variable

rollo.CameraRoll;

Then in a function I use:

rollo.browseForImage ()

But I don't know how to check if there has being an image sellected and how to add it to the stage.

Anybody please?

Thanks