跳转帧上的按钮在 Actionscript 3.0 中不再起作用



这是它应该做的事情:

  1. 主屏幕上有一个开始按钮和一个恢复按钮。
  2. 随着帧的进行,有一个"保存进度并返回主页"按钮,该按钮将保存当前帧并返回主屏幕。
  3. 回到主屏幕,当您单击"恢复"时,它会带您返回 到您所处的前一帧。
  4. 等等
  5. 等等。

我已经完成了 1-3。但是当它返回到您所在的上一帧时,按钮似乎不再起作用。就像,你不能再前进和向前移动帧了。

这是屏幕截图: 截图

然后,以下是上述两个操作脚本的代码:

帧 1:

stop();
start_btn.addEventListener(MouseEvent.CLICK, gotoIntro);
function gotoIntro(event:MouseEvent):void
{
gotoAndStop('intro');
}
resume_btn.addEventListener(MouseEvent.CLICK, gotoLastFrame);
function gotoLastFrame(event:MouseEvent):void
{
gotoAndStop(lastFrame);
trace(currentFrame);
}

帧 2:

var lastFrame:int = currentFrame;
next_btn.addEventListener(MouseEvent.CLICK, gotoNext);
function gotoNext(event:MouseEvent):void
{
nextFrame();
lastFrame++;
trace("current frame: " + currentFrame + "; saved frame: " + lastFrame);
}
back_btn.addEventListener(MouseEvent.CLICK, gotoHome);
function gotoHome(event:MouseEvent):void
{
gotoAndStop('home');
trace(lastFrame);
}

这是为了我将来想做的一部简单的视觉小说。但是哈哈,我已经被困在这里了哈哈哈。有人可以帮忙如何再次向前移动框架吗?非常感谢!

问题是你的框架。框架总是难以管理。转到第 2 帧时,事件侦听器将添加到"下一步"按钮。然后转到第 3 帧,然后转到第 1 帧时,您的按钮将从舞台中删除。然后返回到第 3 帧时,舞台上将添加一个新的"下一步"按钮,但没有事件侦听器(因为您跳过了添加它的第 2 帧(。

一个简单的解决方案是将小说帧与代码一起移动到自己的电影剪辑中,并将其称为"myNovel"作为实例名称。将"开始"屏幕移动到另一个影片剪辑,并将其命名为"myStartScreen"。他们俩都在第 1 帧的舞台上,但你的小说是隐形的。实际上,您在主时间轴上只需要一帧

然后,当您单击开始或下一步时,您将使开始屏幕不可见,您的小说可见。您甚至不需要记住该框架,因为它将保留在您留下的框架中。

主时间线代码:

// make novel invisible at the beginning
myNovel.visible = false;
function gotoHome():void
{
// the novel will stay in the current frame
myStartScreen.visible = true;
myNovel.visible = false;
}
// startFromTheBeginning is an optional parameter
function gotoNovel(startFromTheBeginning:Boolean = false):void
{
// the novel will stay in the current frame
myStartScreen.visible = false;
myNovel.visible = true;
if(startFromTheBeginning)
{
myNovel.gotoAndStop(1);
}
}

开始屏幕代码:

start_btn.addEventListener(MouseEvent.CLICK, gotoIntro);
function gotoIntro(event:MouseEvent):void
{
// parent is the parent moveiclip (your main timeline with the code above)
parent.gotoNovel(true); // start from the beginning
}
resume_btn.addEventListener(MouseEvent.CLICK, gotoLastFrame);
function gotoLastFrame(event:MouseEvent):void
{
parent.gotoNovel(); // this will make the novel visible that are in the frame that the user left
}

小说代码

next_btn.addEventListener(MouseEvent.CLICK, gotoNext);
function gotoNext(event:MouseEvent):void
{
nextFrame();
}
back_btn.addEventListener(MouseEvent.CLICK, gotoHome);
function gotoHome(event:MouseEvent):void
{
parent.gotoHome();
}

最新更新