如何通过AS3中的播放/暂停按钮一次停止多个动画片段

时间:2015-09-06 10:40:34

标签: actionscript-3 flash

我在时间轴上有4个动画片段。这些动画片段有内部动画。它们在时间轴上经典地补间。我必须通过播放/暂停按钮一次停止并播放这四个动画片段。注意到,我已经为此目的使用了以下代码。

它只能停止上层的一个MovieClip,其余3个Movieclip不能通过播放/暂停按钮停止。 (我已尝试所有影片剪辑都在相同的实例名称中,并尝试使用不同的实例)。

这是我的代码:

import flash.events.MouseEvent;


var Playing: Boolean = false;
var lastPosition: Number = 0;

play_btn.addEventListener(MouseEvent.CLICK, onPlayClick);
pause_btn.addEventListener(MouseEvent.CLICK, onPauseClick);


function onPlayClick(event: MouseEvent):void {
    if (Playing == false) {
        Playing = true;
        first_sl.play();
        this.play();
    }
}


function onPauseClick(event: MouseEvent):void {
    Playing = false;
    lastPosition = this.position;
    first_sl.stop();
    this.stop();
}

2 个答案:

答案 0 :(得分:0)

您可以尝试使用stage.stop();停止主时间轴时也使用mc.stop();等。当你玩它们时,使用stage.play();mc.play();

import flash.events.MouseEvent;


var Playing: Boolean = false;
var lastPosition: Number = 0;

play_btn.addEventListener(MouseEvent.CLICK, onPlayClick);
pause_btn.addEventListener(MouseEvent.CLICK, onPauseClick);


function onPlayClick(event: MouseEvent):void {
    if (Playing == false) {
        Playing = true;
        mc.play();
        mc2.play();// other 2 mc's too
        stage.play();
    }
}


function onPauseClick(event: MouseEvent):void {
    Playing = false;
    lastPosition = this.position;
    mc.stop();
    mc2.stop(); // other mc's
    stage.stop();
}

如果您在时间轴上使用最后一个位置也将其用于mc,那么它将同步..
希望这有助于你:)

答案 1 :(得分:0)

要停止主时间轴,您可以使用stop()MovieClip(root).stop()并再次播放,可以使用play()MovieClip(root).play()

var playing: Boolean = false;

btn_play.addEventListener(MouseEvent.CLICK, onPlayClick);
btn_pause.addEventListener(MouseEvent.CLICK, onPauseClick);

function onPlayClick(event: MouseEvent):void
{
    if (!playing) {       
        play();         // you can also use : MovieClip(root).play();   
        mc1.play();
        mc2.play();
        mc3.play();
        mc4.play();
        playing = true;
    }
}

function onPauseClick(event: MouseEvent):void
{
    if (playing) { 
        stop();        // you can also use : MovieClip(root).stop();
        mc1.stop();
        mc2.stop();
        mc3.stop();
        mc4.stop();         
        playing = false;
    }
}

希望可以提供帮助。