ExternalInterface 未链接 javascript 和 actionscript 3

发布于 2024-10-14 03:18:49 字数 2082 浏览 2 评论 0原文

类似的回答问题都没有解决我的问题,所以就这样了。 我想从 JavaScript 调用 actionscript 3 函数,但在 FF 错误控制台中它说我从 JS 调用的函数不存在。它说函数 mover 和 mout 未定义。

这是 JS 文件中的 JS 函数

function getFlashMovieObject(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function playF() {
getFlashMovieObject("Button2").mover();
}
function playB() {
getFlashMovieObject("Button2").mout();
}

这是 HTML 中的代码

<object style="width: 413px; height: 76px;" id="Button2" onMouseOver="playF()"  onMouseOut="playB()">
    <param name="movie" value="homepage/flash/Button2.swf">
    <param value="transparent" name="wmode"/>
    <param value="false" name="loop"/>          
    <embed wmode="transparent" play=false src="homepage/flash/Button2.swf" width="413" height="76" loop="false" swliveconnect="true" name="Button2"></embed>
</object>

和 Actionscript 3 中的代码 我的

ran.stop();
function mover() {
    stopPlayReverse();
this.addEventListener(Event.ENTER_FRAME, playForward, false, 0, true);
}
function mout() {
stopPlayForward();
    this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
function playReverse(e:Event):void {
    if (ran.currentFrame == 1) {
        stopPlayReverse();
    } else {
        ran.prevFrame();
    }
}
function playForward(e:Event):void {
    if (ran.currentFrame == ran.totalFrames) {
    stopPlayForward();
} else {
    ran.nextFrame();
}
}
function stopPlayForward():void {
if (this.hasEventListener(Event.ENTER_FRAME)) {
    ran.removeEventListener(Event.ENTER_FRAME, playForward);
}
}
function stopPlayReverse():void {
    if (this.hasEventListener(Event.ENTER_FRAME)) {
        ran.removeEventListener(Event.ENTER_FRAME, playReverse);
    }
}
ExternalInterface.addCallback("mover", mover);
ExternalInterface.addCallback("mout", mout);

想法是,我想用 javascript 控制鼠标悬停,当我将鼠标悬停在对象上时,电影会正常播放,但是当我将鼠标悬停在对象上时,电影向后播放。我在一层上有影片剪辑,在另一层上有我的 actionsrcript 代码。谁能告诉我我做错了什么?谢谢

None of the similar answered questions fixed my problem, so here it goes.
I want to call actionscript 3 function from JavaScript but in FF error console it says that the function I'm calling from JS does not exist. It says functions mover and mout are not defined.

Here is the JS functions in JS file

function getFlashMovieObject(movieName) {
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function playF() {
getFlashMovieObject("Button2").mover();
}
function playB() {
getFlashMovieObject("Button2").mout();
}

Here's the code in HTML

<object style="width: 413px; height: 76px;" id="Button2" onMouseOver="playF()"  onMouseOut="playB()">
    <param name="movie" value="homepage/flash/Button2.swf">
    <param value="transparent" name="wmode"/>
    <param value="false" name="loop"/>          
    <embed wmode="transparent" play=false src="homepage/flash/Button2.swf" width="413" height="76" loop="false" swliveconnect="true" name="Button2"></embed>
</object>

And the code in Actionscript 3

ran.stop();
function mover() {
    stopPlayReverse();
this.addEventListener(Event.ENTER_FRAME, playForward, false, 0, true);
}
function mout() {
stopPlayForward();
    this.addEventListener(Event.ENTER_FRAME, playReverse, false, 0, true);
}
function playReverse(e:Event):void {
    if (ran.currentFrame == 1) {
        stopPlayReverse();
    } else {
        ran.prevFrame();
    }
}
function playForward(e:Event):void {
    if (ran.currentFrame == ran.totalFrames) {
    stopPlayForward();
} else {
    ran.nextFrame();
}
}
function stopPlayForward():void {
if (this.hasEventListener(Event.ENTER_FRAME)) {
    ran.removeEventListener(Event.ENTER_FRAME, playForward);
}
}
function stopPlayReverse():void {
    if (this.hasEventListener(Event.ENTER_FRAME)) {
        ran.removeEventListener(Event.ENTER_FRAME, playReverse);
    }
}
ExternalInterface.addCallback("mover", mover);
ExternalInterface.addCallback("mout", mout);

The idea is that I want to control the mouse hovering with javascript and when I hover over the object the movie plays normally but when I hover out then the movie plays backwards. I have the movie clip on one layer and on the other layer I have my actionsrcript code. Can anyone tell me what I'm doing wrong? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

﹏雨一样淡蓝的深情 2024-10-21 03:18:49

AS3和JS代码看起来不错,但是您需要在中设置 allowScriptAccess 标志HTML 代码。

The AS3 and JS codes seem fine, but you need to set the allowScriptAccess flag in the HTML code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文