Camera.getCamera problem => solution
When you try to add a camera by name like this:
1 2 | var cameraName:String = "WebCam"; var cam:Camera = Camera.getCamera(cameraName); |
or like this
1 | var cam:Camera = Camera.getCamera(cameranames[0]); |
both return cam = null
Solution:
You need to add camera index like String in order to work
1 2 3 4 5 6 7 8 9 10 11 | var cameraName:String = "WebCam"; var camera:Camera; const imax:int = Camera.names.length; var i:int = 0; while (i < imax) { if (Camera.names[i] == cameraName) { camera = Camera.getCamera(String(i)); break; } i++; } |
or use this function
1 2 3 4 5 6 7 8 9 10 11 12 13 | const camera:Camera = getCamera("webCam"); private static function getCamera($cameraName_:String):Camera { const imax:int = Camera.names.length; var i:int = 0; while (i < imax) { if (Camera.names[i] == $camName_) { return Camera.getCamera(String(i)); } i++; } return null; } |
so now you will have your camera that you wanted:
thank to:
pooja
