« Workaround: FileReference onComplete is not fired on Mac OS | Main | Things I want to see in Adobe Apollo »
June 14, 2006
Camera.getCamera (name) doesn't work in Adobe Flash Player 9 beta
I just noticed that if you have multiple cameras attached to your machine, in that case Camera.getCamera (cameraName) doesn't work Adobe Flash Player 9 beta 3. Camera.getCamera () works fine but that would return the default camera.
But if you want to use multiple cameras in your application, it seems you can't. I have informed Adobe Flash Player team about it and I am sure, it would get fixed.
However, I wanted to see if I am doing any thing wrong in following code. This is the sample code to reproduce the problem. Please let me know (through comments), if there is some problem in code itself. Thanks.
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.media.Camera;
import flash.media.Video;
import flash.events.*;
public class CameraExample extends Sprite
{
private var video1:Video;
private var video2:Video;
private var cameraWidth:int = 640;
private var cameraHeight:int = 480;
public function CameraExample()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
var cameraNames:Array = Camera.names;
trace ("Available cameras: " + cameraNames);
var camera1:Camera = Camera.getCamera(cameraNames[0]);
var camera2:Camera = Camera.getCamera(cameraNames[1]);
if(camera1 != null)
{
camera1.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
video1 = new Video(cameraWidth, cameraHeight);
video1.attachCamera(camera1);
addChild(video1);
}
else
{
trace("Camera1 not working");
}
if(camera2 != null)
{
video2 = new Video(cameraWidth, cameraHeight);
video2.x = cameraWidth + 20;
video2.attachCamera (camera2)
addChild(video2);
}
else
{
trace("Camera2 not working");
}
}
private function activityHandler(event:ActivityEvent):void
{
trace("activityHandler: " + event);
}
}
}
Posted by Abdul Qabiz at June 14, 2006 06:33 PM
Comments
Hi,
you're doing fine, i have noticed the same problem in my as3 projects, happy to hear that you informed Adobe ;)
Posted by: DickRivers at June 22, 2006 03:01 PM
Hi,
I'm only a beginner with action script and i'm working on a project which intends on using up five cameras i've only written the script for the first one using the default .getCamera(), but isent there a difference between using the "names" property which is an array, and the "name" property whhich is a string. On lines 21 and 22 after tracing the camera names should you not use name (string) instead of names (array) to specify the camera. i haven't got access to more than one camera so i can't test this so please let me know if it works as i'll probably need use some similar code.
ws
Posted by: WillSells at August 3, 2006 02:17 PM
I ran into this same bug. Please let me know if you find a workaround. I couldn't find references to it as a "known issue" on the Flex Developers' Site.
Posted by: Nolan Love at August 19, 2006 04:58 PM
Hello,
I ran into the same problem. It seems that you need to pass the index instead of the name to getCamera. So, the following code will work:
var camera1:Camera = Camera.getCamera("0");
var camera2:Camera = Camera.getCamera("1");
The index corresponds to the Array index in Camera.names. To loop through the attached cameras:
for (var i :String in Camera.names)
{
var name :String = Camera.names[i];
var cam :Camera = Camera.getCamera( i );
}
Have a look at my recent article on cameras for more info.
Posted by: Sander Kruger at February 20, 2007 02:11 PM