我知道有很多關於這個問題的文章和論壇帖子,很多都不起作用,仍然沒有答案。有些教程聲稱他們的代碼有效,但其中一些教程沒有下載頁面,其中一些教程下載頁面,鏈接不起作用。此外,也許有一種新的方式來做到這一點,我發現的代碼不再受支持。Javascript調用AS3函數
這裏是我的代碼:HTML和Javascript
<html>
<head><title>Javascript to SWF</title>
<script language="JavaScript">
function getFlashMovie(movieName) {
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
}
function callToActionscript()
{
getFlashMovie("jscallswf").setMouseXY();
}
callToActionscript();
</script>
</head>
<body style="background:red;">
<body>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="450" id="jscallswf" align="middle" data="jscallswf.swf" style="height: 250">
<param name="allowScriptAccess" value="sameDomain">
<param name="allowFullScreen" value="false">
<param name="movie" value="jscallswf.swf">
<param name="quality" value="High"><param name="bgcolor" value="#ffffff">
<embed src="jscallswf.swf" quality="High" bgcolor="#ffffff" width="400" name="jscallswf" align="middle" allowscriptaccess="sameDomain" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" style="height: 250">
</object>
</body>
</body>
</html>
AS3代碼:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("setMouseXY", rotateCam);
function rotateCam()
{
td.text = "NEWTEXT";
}
這裏是另一個JavaScript方法:
<html>
<head><title>Javascript to SWF</title>
<style type="text/css">
#jscallswf {
margin:300px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"> </script>
<script type="text/javascript" src="swfobject.js"></script>
<script language="JavaScript">
// JS Code
// Embedding through SWFObject rocks in comparison with Adobe's garbage:
var flashvars = {};
var params = {};
params.menu = "false";
params.salign = "t";
params.scale = "noscale";
params.wmode = "transparent";
params.allowScriptAccess = "always";
var attributes = {};
attributes.id = "jscallswf";
swfobject.embedSWF("jscallswf.swf", "flashDiv", "274", "246", "9.0.0", "", flashvars, params, attributes);
// Functions needed for calling Flex ExternalInterface
function thisMovie(movieName)
{
if (navigator.appName.indexOf("Microsoft") != -1)
{
return window[movieName];
}
else
{
return document[movieName];
}
}
function callFlashMethod()
{
thisMovie("jscallswf").setMouseXY();
}
$(document).ready(function(){
callFlashMethod();
});
</script>
</head>
<body style="background:red;">
<body>
<div id="flashDiv" style="margin:200px;"></div>
</body>
</body>
</html>
兩個返回錯誤控制檯「遺漏的類型錯誤:不能調用未定義的方法'setMouseXY'「
也許你太早打電話給他們測試? –