[英]Cannot get JS to trigger As3 function in swf
Desperately need help and would be gretaful if someone could see if they can find what is wrong. 迫切需要帮助,如果有人看到他们是否能找到问题所在,那将是令人不快的。
I am trying to trigger a swf movie embedded in web page by using a js function. 我试图通过使用js函数来触发嵌入在网页中的swf电影。 This is a dry run using sample code I have found, i eventually just want the movie to play and stop via js instructions, when clicking an a href. 这是使用我发现的示例代码进行的试运行,我最终只想在单击a href时通过js指令播放和停止播放电影。 Website is http://simplywebdzine.com/ASJS_test.html 网站是http://simplywebdzine.com/ASJS_test.html
The as3 code in the swf is: swf中的as3代码为:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript);
function getTextFromJavaScript(str):void {
trace(str);
}
THANK YOU 谢谢
Adding full HTML : 添加完整的HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function setCurrentPage(newPage) {
currentPage = newPage;
SendDataToFlashMovie(newPage);
}
function getFlashMovieObject(movieName){
if (window.document[movieName]){
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1){
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else{
return document.getElementById(movieName);
}
}
function SendDataToFlashMovie(newPage){
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.sendTextToFlash(newPage);
}
</script>
</head>
<body>
<a href="#" onClick="setCurrentPage('Home')">Home</a>
<object height="250" width="380" id="myFlashMovie"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash
/swflash.cab#version=8" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param value="myFlashMovie.swf" name="movie">
<param value="high" name="quality">
<param value="transparent" name="wmode">
<param value="#FFFFFF" name="bgcolor">
<param value="true" name="allowFullScreen">
<param value="true" name="swLiveConnect">
<param value="always" name="allowScriptAccess">
<embed height="250" align="middle" width="380" src="myFlashMovie.swf" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer" play="false"
loop="false" scale="showall" wmode="transparent" devicefont="false"
bgcolor="#000000" menu="true" allowfullscreen="false" allowscriptaccess="always"
salign="" type="application/x-shockwave-flash" name="myFlashMovie">
</object></body>
</html>
确保在Flash嵌入中添加允许脚本访问参数(通常是问题所在)
<param name="allowScriptAccess" value="always" />
Looks like you have a typo in the html code you linked to. 看起来您在链接到的html代码中有错字。 You have this code: 您有以下代码:
<a href onclick="javascript:SendDahMovie();">trigger</a>
But the JS function you defined is: 但是您定义的JS函数是:
function SendDataToFlashMovie(newPage){
var flashMovie=getFlashMovieObject("myFlashMovie");
flashMovie.sendTextToFlash(newPage);
}
Every time you click on the trigger
link, no only your function is not called, but also the page reloads. 每次单击trigger
链接时,不仅不会调用您的函数,而且还会重新加载页面。 So try fixing this name mismatch. 因此,请尝试解决此名称不匹配的问题。
PS: By the way, your code actually works. PS:顺便说一下,您的代码实际上是有效的。
I ran this JS code from firebug: 我从firebug中运行了这个JS代码:
SendDataToFlashMovie('testing');
And I can see the trace in flashlog.txt. 我可以在flashlog.txt中看到跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.