Reputation: 124
Can you use the camera of an iOS device in an AS3 app? If so, how?
Upvotes: 2
Views: 3927
Reputation: 3871
Yep it's really easy, there are many ways to access the camera in AS3.
Firstly, the same way as you access the camera in normal AS3 applications:
var camera:Camera = Camera.getCamera();
var video=new Video();
video.attachCamera(camera);
this.addChild(video);
This will display the camera in the current display object.
You can also ask for images from the Camera roll using the CameraRoll class:
import flash.media.CameraRoll;
var cameraRoll:CameraRoll = new CameraRoll();
if(CameraRoll.supportsBrowseForImage)
{
cameraRoll.addEventListener(MediaEvent.SELECT, imageSelected);
cameraRoll.addEventListener(Event.CANCEL, browseCancelled);
cameraRoll.addEventListener(ErrorEvent.ERROR, mediaError);
// Ask the user to select an image
cameraRoll.browseForImage();
}
You can use the native "camera" application to take a photo:
import flash.media.CameraUI;
var cameraUI:CameraUI = new CameraUI();
if (CameraUI.isSupported )
{
cameraUI.addEventListener(MediaEvent.COMPLETE, imageSelected);
cameraUI.addEventListener(Event.CANCEL, browseCancelled);
cameraUI.addEventListener(ErrorEvent.ERROR, mediaError);
cameraUI.launch(MediaType.IMAGE);
}
Hope that points you in the right direction.
Upvotes: 6