使用ExternalInterface调用Flash函数
我在通过使用ExternalInterface 调用函数时遇到问题。
首先,这是 HTML/JS 方面:
<p align="right">
<object type="application/x-shockwave-flash" data="camera.swf"
width="200" height="200" align="right" id="camSWF">
<param name="movie" value="camera.swf" align="right" />
<param name="allowScriptAccess" value="always" />
</object></p>
<script type="text/javascript">
var flashObj = document.getElementById('camSWF');
document.onmousemove = setMouseXY;
function setMouseXY(e) {
var x = e.pageX;
var y = e.pageY;
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
}
</script>
其次,这是 ActionScript 2 代码:
ExternalInterface.addCallback('setMouseXY', null, rotateCam);
function rotateCam(mouseX, mouseY, docWidth, docHeight)
{
// DO STUFF
}
据我所知,一切都应该有效,但显然我遗漏了一些东西。
每当鼠标事件在 HTML 页面上触发时,我都会在 Firebug 中收到此错误:
flashObj.rotateCam is not a function:
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
我陷入困境。也许这是一些安全问题?
I'm having trouble calling a function through the use of ExternalInterface.
First off, here's the HTML/JS side:
<p align="right">
<object type="application/x-shockwave-flash" data="camera.swf"
width="200" height="200" align="right" id="camSWF">
<param name="movie" value="camera.swf" align="right" />
<param name="allowScriptAccess" value="always" />
</object></p>
<script type="text/javascript">
var flashObj = document.getElementById('camSWF');
document.onmousemove = setMouseXY;
function setMouseXY(e) {
var x = e.pageX;
var y = e.pageY;
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
}
</script>
And secondly, here is the ActionScript 2 code:
ExternalInterface.addCallback('setMouseXY', null, rotateCam);
function rotateCam(mouseX, mouseY, docWidth, docHeight)
{
// DO STUFF
}
As far as I can see, everything should work, but obviously I'm missing something.
Whenever the mouse event fires on the HTML page, I get this error in Firebug:
flashObj.rotateCam is not a function:
flashObj.rotateCam(x, y, $(document).width(), $(document).height());
I'm quite stuck. Perhaps it's some security thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该语句添加“rotateCam”作为“setMouseXY”的回调函数。所以“setMouseXY”是必须从 javascript 调用的函数。
This statement adds "rotateCam" as the callback function for "setMouseXY". So "setMouseXY" is the function that has to be called from javascript.