Skip to main content
SheaB
Inspiring
August 5, 2017
Answered

Add play/pause/play button to control movie clip playback

  • August 5, 2017
  • 1 reply
  • 4130 views

I'm using Animate CC, ActionScript 3.0.

I've got a movie clip on the main time line and a play button. When the file is exported to a .SWF file the play button works fine to play the movie clip. However, I need to add a play/pause/play function. The play button should perform as follows:

Click play button once = plays the movie clip

Click same button = pauses the movie clip.

Click same button = resumes play of the movie clip from the point it was stopped (not from the beginning).

Here's the AS on the main time line, movie clip name is "TimeElapse":

TimeElapse.stop();

function startTimeElapse(event:MouseEvent):void

{

    TimeElapse.play();

}

startButton1.addEventListener(MouseEvent.CLICK, startTimeElapse);

Inside the movie clip on the last frame I have AS: stop();

I am happy to upload the file if needed, I have a very simple sample file I'm playing around with to try to get the play/pause/play function to work. Any assistance is greatly appreciated!

This topic has been closed for replies.
Correct answer Ned Murphy

Try something like...

var playing:Boolean = false;

TimeElapse.stop();

function startTimeElapse(event:MouseEvent):void

{

    if(playing){

           TimeElapse.stop();

    } else {

           TimeElapse.play();

    }

    playing = !playing;

}

startButton1.addEventListener(MouseEvent.CLICK, startTimeElapse);

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
August 5, 2017

Try something like...

var playing:Boolean = false;

TimeElapse.stop();

function startTimeElapse(event:MouseEvent):void

{

    if(playing){

           TimeElapse.stop();

    } else {

           TimeElapse.play();

    }

    playing = !playing;

}

startButton1.addEventListener(MouseEvent.CLICK, startTimeElapse);

SheaB
SheaBAuthor
Inspiring
August 5, 2017

Thanks Ned, that's not working. Should I be adding to existing actions or just as is? Perhaps I'm trying it wrong.

Colin Holgate
Inspiring
August 5, 2017

Keep this line:

startButton1.addEventListener(MouseEvent.CLICK, startTimeElapse);

but replace the other lines you showed with Ned's version. The whole thing would be:

var playing:Boolean = false;

TimeElapse.stop();

function startTimeElapse(event:MouseEvent):void

{

    if(playing){

           TimeElapse.stop();

    } else {

           TimeElapse.play();

    }

    playing = !playing;

}

startButton1.addEventListener(MouseEvent.CLICK, startTimeElapse);