Skip to main content
Known Participant
Aug 17, 2011 5:40 AM UTC
Answered

Access to the Camera Roll AS3 Flash CS5.5

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 is closed to new replies. Start a new post to keep the conversation going.
Colin Holgate
Colin HolgateCorrect answer
Inspiring
Aug 17, 2011 11:26 PM UTC

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

}

20 replies

Aug 17, 2011 10:49 PM UTC

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.

Translate
Colin Holgate
Colin HolgateCorrect answer
Inspiring
Aug 17, 2011 11:26 PM UTC

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

}

Translate
Known Participant
Aug 18, 2011 5:05 AM UTC

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!

Translate
Pahup
Adobe Employee
Adobe Employee
Aug 17, 2011 5:44 AM UTC
Known Participant
Aug 17, 2011 6:41 AM UTC

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?

Translate
Known Participant
Aug 17, 2011 7:44 AM UTC

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

Translate