gpt4 book ai didi

javascript - JavaScript 与 Flash 之间的通信

转载 作者:行者123 更新时间:2023-12-02 19:46:26 25 4
gpt4 key购买 nike

我已经添加了:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com