AS3:如何跳到另一个场景(或框架序列),然后返回从跳跃的框架



现在,我正在建立一场运动比赛的模拟,分别在两个线性的一半中进行,在两个单独的场景中分开。当得分发生时,在比赛中得分的进球作为按钮出现。该按钮可以作为重播目标的参考。在下半场(场景2)时,应该可以访问上半场(场景1)的目标(场景1)。我为每个目标创建了额外的场景,这些场景用作单独的重播。

我想让用户能够做到的是,在任何选择的时间中单击"重播"按钮,查看重播,然后返回到最初跳跃的确切帧源自,并在首选时从那里开始玩。

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

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

如果我找出如何用另一个替换一个,则可以适合。

另一个我想使用currentFrame和/或currentLabel方法,但我不知道该怎么。

我有项目.fla file可以使您对事物有更清晰的见解。

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

在时间轴的第一帧中,创建以下var和功能:

//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();