假设我有这个AS3代码:
playButtonContainer.addEventListener(MouseEvent.CLICK, playButtonClicked);
function playButtonClicked(evt:MouseEvent) {
instructionsContainer.gotoAndPlay(2);
analysisScreenContainer.gotoAndPlay(2);
playButtonContainer.gotoAndPlay(2);
statusDescriptionContainer.gotoAndPlay(2);
}
在instructionsContainer
、analysisScreenCnotainer
、playButtonContainer
和statusDescriptionContainer
里面是一个电影剪辑,它有自己的时间轴和动画。
如您所见,我有 4 个不同的影片剪辑一个接一个地播放。我该如何使它
statusDescriptionContainer.gotoAndPlay(2);
仅在动画之后执行
playButtonContainer.gotoAndPlay(2);
完成执行和
playButtonContainer.gotoAndPlay(2);
仅在
playButtonContainer.gotoAndPlay(2);
动画完成?
切尔尼夫建议你什么,或者你可以添加一个事件侦听器,只听输入帧。在那里,您只需检查当前帧是否等于总帧数。或者,您可以扩展影片剪辑:
package {
import flash.display.MovieClip;
import flash.events.Event;
public class AdvancedMovieClip extends MovieClip {
public function AdvancedMovieClip() {
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
if(this.currentFrame == this.totalFrames) {
dispatchEvent(new Event(Event.COMPLETE));
}
}
public function destroy():void {
this.stop();
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
}
}
}
你可以尝试这样的事情:
playButtonContainer.addEventListener(MouseEvent.CLICK, playButtonClickedHandler, false, 0, true);
function playButtonClickedHandler(event:MouseEvent):void
{
trace('instructionsContainer');
instructionsContainer.addFrameScript(instructionsContainer.totalFrames -1, playStatusDescriptor);
instructionsContainer.gotoAndPlay(2);
}
function playStatusDescriptor():void
{
instructionsContainer.stop();
trace('statusDescriptionContainer');
statusDescriptionContainer.addFrameScript(statusDescriptionContainer.totalFrames -1, playAnalysisScreen);
statusDescriptionContainer.gotoAndPlay(2);
}
function playAnalysisScreen():void
{
statusDescriptionContainer.stop();
trace('playAnalysisScreen');
analysisScreenContainer.addFrameScript(analysisScreenContainer.totalFrames -1, playAnotherButton);
analysisScreenContainer.gotoAndPlay(2);
}
function playAnotherButton():void
{
analysisScreenContainer.stop();
trace('playAnotherButton');
anotherScreenContainer.addFrameScript(anotherScreenContainer.totalFrames -1, somethingElse);
anotherScreenContainer.gotoAndPlay(2);
}
function somethingElse():void
{
anotherScreenContainer.stop();
trace('somethingElse');
}