在动画CC中,(动作脚本3)我有4帧需要顺序进入" A"或" D"按下按钮是这样的:
<(>(((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();
&#13;
第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();
&#13;
第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();
&#13;
第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();
&#13;
我也尝试过使用prevFrame();和nextFrame();但同样的问题让我相信我的顺序逻辑是合理的,但我的事件听众是问题,请有人能为我阐明这一点。
答案 0 :(得分:4)
你的事情过于复杂。您不需要每个框架中的脚本,只需要一个通用的导航脚本来管理所有脚本。
选项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 容器,并从外部导航它会更好。像你一样混合框架和脚本会给你带来很多痛苦。