2013-07-19 41 views
1

我试图检查用户是否有swf文件的摄像头。AS3外部接口不调用,回调不起作用

但外部接口调用不被执行,以及回调说错误:

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; 
      } 

     } 
    } 

} 

有人看到我的错误? 为什么这不起作用?

thx。

+0

alllert调用功能是否正确? – Harold

+0

看看这个:'[LINK](http://bytes.com/topic/flash/answers/694359-how-do-i-access-flash-function-using-javascript)',请关注js getMovie () 方法。 – Alex

回答

2

这不起作用,因为我在本地尝试。

我已经上传我的代码在FTP中,这工作正常。

Thx for all reply。