我尝试检查用户是否有带有 swf 文件的相机。
但是没有执行外部接口调用,并且回调说错误:
Uncaught TypeError: Object #<HTMLObjectElement> has no method 'checkWebcam'
这是我的 html 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>webcamDetector</title>
<meta name="description" content="" />
<script src="js/swfobject.js"></script>
<script>
var flashvars = {
};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "",
wmode: "direct" // can cause issues with FP settings & webcam
};
var attributes = {
id:"webcamDetector"
};
swfobject.embedSWF(
"webcamDetector.swf",
"altContent", "1", "1", "10.0.0",
"expressInstall.swf",
flashvars, params, attributes);
function alllert(test){
console.log(test);
}
</script>
<style>
html, body { height:100%; overflow:hidden; }
body { margin:0; }
</style>
</head>
<body>
<div id="altContent">
<h1>webcamDetector</h1>
<p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
</div>
<div onclick="alert(document.getElementById('webcamDetector').checkWebcam());">test</div>
</body>
</html>
这是我的 as3 主文件:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.external.*;
import flash.media.Camera;
/**
* ...
* @author
*/
public class Main extends Sprite
{
public function Main():void
{
ExternalInterface.call("alllert", "tedsf dfds fsd f");
ExternalInterface.addCallback("webcam",checkWebcam);
ExternalInterface.addCallback("checkWebcam", checkWebcam);
}
public function checkWebcam():int {
if (Camera.isSupported) {
var webcam:Array = Camera.names;
if (webcam.length > 0) {
return 58;
}else {
return 59;
}
}else {
return 60;
}
}
}
}
有人看到我的错误吗?为什么这不起作用?
谢谢。