使用ExternalInterface调用Flash函数

发布于 2024-12-21 19:49:00 字数 1104 浏览 1 评论 0原文

我在通过使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮云落日 2024-12-28 19:49:00
ExternalInterface.addCallback('setMouseXY', null, rotateCam);

该语句添加“rotateCam”作为“setMouseXY”的回调函数。所以“setMouseXY”是必须从 javascript 调用的函数。

function setMouseXY(e) {
    var x = e.pageX;
   var y = e.pageY;
   flashObj.setMouseXY(x, y, $(document).width(), $(document).height());
}
ExternalInterface.addCallback('setMouseXY', null, rotateCam);

This statement adds "rotateCam" as the callback function for "setMouseXY". So "setMouseXY" is the function that has to be called from javascript.

function setMouseXY(e) {
    var x = e.pageX;
   var y = e.pageY;
   flashObj.setMouseXY(x, y, $(document).width(), $(document).height());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文