Actionscript 导航不起作用

Posted

技术标签:

【中文标题】Actionscript 导航不起作用【英文标题】:Actionscript navigation not working 【发布时间】:2018-04-01 10:37:03 【问题描述】:

在动画 CC 中,(动作脚本 3)当按下“A”或“D”按钮时,我有 4 帧需要按顺序进行:

(((((1 -> 2 -> 3 -> 4|||然后返回|||4 -> 3 -> 2 -> 1)))))

这工作正常,但是当我在上述序列之后回到第 1 帧时,单击下一步将我一直发送到第 4 帧(使用跟踪我发现所有事件侦听器都已触发,但我不知道为什么)

下面是每一帧的代码:

第 1 帧

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram);
function nextFram(e:KeyboardEvent):void
if (currentLabel == "home" && e.keyCode == Keyboard.D)
	trace("gotobuttonpage");
	gotoAndPlay("buttonPage");
	removeEventListener(KeyboardEvent.KEY_DOWN, nextFram);
	trace("event listener removed");
	
 

stop();

第 2 帧

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram2);
function nextFram2(e:KeyboardEvent):void
if (currentLabel == "buttonPage" && e.keyCode == Keyboard.D)
	trace("gotovideopage");
	gotoAndPlay("videoPage");
	removeEventListener(KeyboardEvent.KEY_DOWN, nextFram2);
	trace("event listener removed");
	
 

stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram2);
function backFram2(e:KeyboardEvent):void
if (currentLabel == "buttonPage" && e.keyCode == Keyboard.A)
	trace("backtohomepage");
	gotoAndPlay("home");
	removeEventListener(KeyboardEvent.KEY_DOWN, backFram2);
	trace("event listener removed");
	
 

stop();

第 3 帧

stage.addEventListener(KeyboardEvent.KEY_DOWN, nextFram3);
function nextFram3(e:KeyboardEvent):void
if (currentLabel == "videoPage" && e.keyCode == Keyboard.D)
	trace("gotoendpage");
	gotoAndPlay("endPage");
	removeEventListener(KeyboardEvent.KEY_DOWN, nextFram3);
	trace("event listener removed");
 

stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram3);
function backFram3(e:KeyboardEvent):void
if (currentLabel == "videoPage" && e.keyCode == Keyboard.A)
	trace("gotobuttonpage!");
	gotoAndPlay("buttonPage");
	removeEventListener(KeyboardEvent.KEY_DOWN, backFram3);
	trace("event listener removed");
 

stop();

第 4 帧

stage.addEventListener(KeyboardEvent.KEY_DOWN, backFram4);
function backFram4(e:KeyboardEvent):void
if (currentLabel == "endPage" && e.keyCode == Keyboard.A)
	trace("backtovideopage");
	gotoAndPlay("videoPage");
	removeEventListener(KeyboardEvent.KEY_DOWN, backFram4);
	trace("event listener removed");
	
 

stop();

我也尝试过使用 prevFrame();和下一个帧();但是发生了同样的问题,导致我相信我的顺序逻辑是合理的,但我的事件监听器是问题所在,请有人为我解释一下。

【问题讨论】:

【参考方案1】:

你把事情复杂化了。您不需要在每一帧中都使用脚本,只需要一个通用的导航脚本即可。

选项 1

// Frame 1 script.

var Frames:Array;
var currentPage:int;

// Initialize for the first time.
if (!Frames)

    stop();

    // Subscribe for the keyboard event just this once.
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
    Frames = ["home", "buttonPage", "videoPage","endPage"];

    // Go to the first page, if necessary.
    naviGate(-100);


function naviGate(value:int):void

    // Shift the current page.
    currentPage += value;

    // Fix the ranges.
    if (currentPage < 0)
    
        currentPage = 0;
    

    if (currentPage >= Flames.length)
    
        currentPage = Frames.length - 1;
    

    // Go to designated frame.
    gotoAndStop(Frames[currentPage]);


// Now, simple keypress handling.
function onKey(e:KeyboardEvent):void

    switch (e.keyCode)
    
        case Keyboard.A:
            naviGate(-1);
            break;

        case Keyboard.D:
            naviGate(1);
            break;
    

选项 2

最好将帧放入某个 MovieClip 容器中,并从外部对其进行导航。像你那样混合框架和脚本,会给你带来很多痛苦。

【讨论】:

以上是关于Actionscript 导航不起作用的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript - 联系表单不起作用

为啥movieclip中的按钮不起作用(actionscript 2)

actionscript 2 影片剪辑事件不起作用

Actionscript 3 实例名称属性不起作用

Actionscript 2.0 if 和 else 功能不起作用?

设置可见性槽属性不起作用 actionscript 3.0