我用JavaScript调用Flex方法开启摄像头的方法总是失败。但是Flex直接在CreatComplete方法里面调用开启摄像头的方法是成功的。有人说是安全沙箱的问题,我在我的asp.net根目录下扔了一个crossdomain.xml文件也没用。请大神帮助提供解决的方案。
flex代码:
public function init():void{
ExternalInterface.addCallback("openCamera", setupCamera);
}
//初始化摄像头
public function setupCamera():void{
//启动摄像头
cam = Camera.getCamera();
if(cam != null){
cam.addEventListener(StatusEvent.STATUS,onStatusHandler);
cam.addEventListener(ActivityEvent.ACTIVITY,onActiveHandler);
cam.setMode(320,240,30);
cam.setQuality(0,100); //设置清晰度
vi = new Video();
vi.width = 320;
vi.height = 240;
vi.attachCamera(cam);
vdisplay.addChild(vi);
}
}
private function onActiveHandler(event:ActivityEvent):void
{
if(!cam.muted){ //判断摄像头存不存在
startRec.enabled = true;
}else{
Alert.show("错误2:无法链接到活动摄像头!");
}
cam.removeEventListener(StatusEvent.STATUS,onStatusHandler);
}
private function onStatusHandler(event:StatusEvent):void{
if(!cam.muted){ //判断摄像头存不存在
startRec.enabled = true;
}else{
Alert.show("错误1:无法链接到活动摄像头!")
}
cam.removeEventListener(StatusEvent.STATUS,onStatusHandler);
}
JS:
<script type="text/javascript" language=javascript>
function openCamera() {
document.getElementById("v").openCamera();
}
html: