AS3:如何跳转到另一个场景(或帧序列)并 return 回到跳出的帧

AS3: How to jump to another scene (or frame sequence) and return back to frame having jumped from

现在我正在构建一场体育比赛的模拟,分为 2 个线性半场,分为 2 个独立的场景。在比赛中得分的目标在得分发生时显示为舞台上的按钮。该按钮用作重播目标的参考。比方说上半场(场景 1)的进球应该可以在下半场(场景 2)重播。 我为每个目标创建了额外的场景,作为个人重播的参考。

我希望用户能够在任何选择的时间单击重播按钮,查看重播,然后return 到它最初从 跳转的确切帧,并在需要时从那里继续播放。

我 'cannot' 使用 movieClipsaddChild 方法的原因是我希望最终的 SWF 保持其透明背景,因为我将把它嵌入 html 稍后。

如果(以及如何?)我使用 addChild 方法,您会同时看到 2 个部分透明的 movieClips movieClips,运行。

如果我知道如何用另一个替换一个,这可能是合适的方法。

我猜另一个人会使用 currentFrame and/or currentLabel 方法,但我不知道该怎么做。

我有项目 .fla file 让你对事物有更清晰的认识。

假设您有一个实例名称为 replayBtn 的重播按钮。这是一种设置方法:

在时间轴的第一帧,创建以下变量和函数:

//define a variable to hold the last replay frame
var lastReplayFrame:int = 0;

//define a variable to hold the frame to go back to once a replay is done
var replayReturnFrame:int = 0;

//create a function to call after a replay is done
function replayReturn(){
    //if we've set a frame to jump back to
    if(replayReturnFrame > 0){
        //go there and resume playing
        this.gotoAndPlay(replayReturnFrame);

        //reset the return frame so we don't go back there the next time if the button isn't hit
        replayReturnFrame = 0;
    }
}

//create the click handler for the replay button:
function replayClick(e:Event):void {
    //check if there is a replay available
    if(lastReplayFrame > 0){
        //store the current frame before jumping back
        replayReturnFrame = this.currentFrame;

        gotoAndPlay(lastReplayFrame);
    }
}

//add the click event listener to the replay button instance
replayBtn.addEventListener(MouseEvent.CLICK, replayClick);

现在,在您的时间轴中,每当目标开始时(例如回放应该开始的第一帧),将以下代码放在关键帧上:

lastReplayFrame = this.currentFrame;

然后,在回放的最后一帧,将此代码放在关键帧上:

replayReturn();