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

时间:2016-06-14 13:48:17

标签: actionscript-3 flash-cs6

现在我正在建立一个体育比赛的模拟,以2个线性两半进行,分为两个不同的场景。已经得分的目标在得分发生时显示为舞台上的按钮。该按钮用作重放目标的参考。进球得分让我们说上半场(场景1)应该可以在下半场重播(场景2)。 我已经为每个目标创建了额外的场景,作为单独的重播来引用。

我希望用户能够在任何选定的时间点击重播按钮 ,查看重播,然后返回原始跳转的确切帧来自,并在首选时播放。

我不能'使用movieClipsaddChild方法,我希望最终的SWF保持其透明背景,因为我稍后会将其嵌入到html中。

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

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

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

我有项目.fla file,可以让您更清楚地了解事情。

1 个答案:

答案 0 :(得分:1)

假设您有一个实例名称为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();