我正在尝试获得一个
ExternalInterface调用工作的基本示例。目标:发送一个字符串到一个闪存对象,并让它返回它,然后我可以console.log。
当我试图调用闪存对象上的方法时,我一直得到Uncaught TypeError: undefined is not a function。
我在object和embed标记中都使用了$(window).on("load"),并且我正在检查setTimeout()和使用$(window).on("load")而不是$(document).ready();都没有任何争用条件--但是我仍然得到了上面的错误。
我在flash动画的第一个关键帧中放置了以下actionscript:
import flash.external.*;
import flash.system.*;
// Params: First the function to call in JS, second the function run within AS
ExternalInterface.addCallback("test", sayHerro);
function sayHerro():String {
return "HERRO OMFG";
}因此,我定义了一个函数,sayHerro(),它不接受参数并返回一个String。这应该在我的JavaScript在swf对象上调用test时执行。
下面是保存主体中元素的HTML:
<object height="640" id="myFlashMovie"> // note the id is myFlashMovie
<param value="inbanner-mpu.swf" name="movie" />
<param value="true" name="swLiveConnect" /> // Apparently I need this...
<param value="always" name="allowScriptAccess" /> // and also this...
// Note the src is the same as above (the animation does display), the name is the same, and this also has the allowscriptaccess tag
<embed height="640" src="inbanner-mpu.swf" allowscriptaccess="always" type="application/x-shockwave-flash" name="myFlashMovie"></embed>
</object>最后,这里是我的JavaScript,它在执行和尝试调用swf对象上的test()之前等待半秒钟。
<script type="text/javascript">
$(window).on("load", function() {
setTimeout(function() {
var swf = document.getElementById("myFlashMovie");
console.log(swf);
swf.test();
}, 500);
});
</script>我为什么要拿到TypeError?我一定是在做一些很愚蠢的事情,但我只是不知道我的问题在哪里。
在相关情况下:
https://stackoverflow.com/questions/23135985
复制相似问题