javascript - JavaScript 与 Flash 之间的通信

标签 javascript html actionscript-3

我已经添加了:

ExternalInterface.addCallback('sendToActionScript', setKeyboardFocus);
ExternalInterface.call("setFocus", 'pathfinder');

在我的主类的 init() 函数中。

在 html 中我有这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>pathFinder</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css" media="screen">
    html, body { height:100%; background-color: #333333;}
    body { margin:0; padding:0; overflow:hidden; }
    #flashContent { width:100%; height:100%; }
    </style>
 <script type="text/javascript">



 function getFlashMovie(movieName) {
 var isIE = navigator.appName.indexOf("Microsoft") != -1;
 return (isIE) ? window[movieName] : document[movieName];
 }



function callToActionscript(str) 
{  

var fm = getFlashMovie("pathfinder");

fm.sendToActionScript(str);
}

function setFocus(id){ 

 var f =  document.getElementById(id);
 f.focus();
 callToActionscript('test') 

 } 


</script>
</head>
<body>



    <div id="flashContent" align='center'>
<table width="100%" height="100%" border="0" align="center" cellpadding="0"  
cellspacing="0">
<tr>
  <td align="center" valign="middle" bgcolor="#333333"><table width="1050" border="0"       
cellpadding="0" cellspacing="0">

    <tr>
      <td>
    <div align="center">
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#versio
 n=6,0,0,0" 
WIDTH="1050" 
HEIGHT="600" 
id="pathfinder" 
ALIGN="middle">
<PARAM NAME=movie VALUE="pathFinder.swf"> 
<PARAM NAME=quality VALUE=high> 
<PARAM NAME=bgcolor VALUE=#333333> 
<EMBED src="pathFinder.swf" quality=high bgcolor=#333333 WIDTH="1050" HEIGHT="600" 
NAME="pathfinder" ALIGN="middle" TYPE="application/x-shockwave-flash" 
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always"> 
</EMBED> </OBJECT></div></td></tr></td></tr></table>

    </div>
</body></html>

在主阶段,我有一个动态文本字段实例“test_txt”来检查该函数是否被调用。

所以在ExternalInterface代码之后我有:

private function setKeyboardFocus(str:String):void {
stage.addEventListener(KeyboardEvent.KEY_DOWN,checkKeysDown);
stage.addEventListener(KeyboardEvent.KEY_UP,checkKeysUp)
test_txt.text = str
}

问题是 flash 没有获得键盘焦点(KeyboardEvent 的事件监听器永远不会添加),函数 setKeyboardFocus 永远不会被调用。

有什么帮助吗?

最佳答案

根据我找到的一个消息来源,您需要添加 allowScriptAccess="always"在两个地方。

  1. 你有它的地方,在 <EMBED ... allowScriptAccess="always"> </EMBED>堵塞。
  2. 您还需要<PARAM NAME="allowScriptAccess" VALUE="always" >与其他 PARAM block

关于javascript - JavaScript 与 Flash 之间的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9828389/

相关文章:

html - 添加指向某些内容的链接时,如何防止不必要的更改?

javascript - 我可以更改网页的比例吗?

apache-flex - 如何使用代码保护我的 Flash/Flex SWF?

actionscript-3 - IOError 2032 有时会发生

php - 从 html 链接调用 AS3 函数 - Javascript? PHP? swf地址?

javascript - 从 MediaSource 播放时无法搜索视频

javascript - 如何在 Javascript 中读取 JSON(服务器响应)?

javascript - 这个 jQuery 元素的 innerHTML 语句有什么问题?

javascript - JQuery 窗口对象滚动顶部功能

javascript - 如何将 ‘google-services.json’ 文件添加到 Meteor/Cordova 项目?