• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Problem with Play Pause AS3 button on main timeline

Community Beginner ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

Wondered if anyone can help with this? Have been trying to create a play/pause button for the main timeline in my flash movie.

Created a movie clip with 1st frame - a pause graphic, then on 2nd frame - play graphic, labelled the frames 'pause' and 'play' consecutively and put a stop action on the first frame of the movieclip.

Then put the following code in the actions layer of the main timeline (and gave instance name of 'ppBtn' to the movieclip):

var pp:Boolean = true;


function ppState(event:MouseEvent) {

if(pp) {

stop();

event.target.gotoAndStop('pause');

pp = false;

}else{

play();

event.target.gotoAndStop('play');

pp = true;

}

}

ppBtn.addEventListener(MouseEvent.CLICK, ppState);

It works in stopping and starting the movie but the actual movieclip doesn't toggle between the pause and the play graphics (just stays on the 'pause' state - 1st frame). Any help on this much appreciated!

thanks

TOPICS
ActionScript

Views

5.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jan 28, 2011 Jan 28, 2011

Which answer was helpful (correct) ?  Could you mark it?

Votes

Translate

Translate
Advocate ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

try:

var pp:Boolean = true;


function ppState(event:MouseEvent) {

if(pp) {

stop();

ppBtn.gotoAndStop('pause');

pp = false;

}else{

play();

ppBtn.gotoAndStop('play');

pp = true;

}

}

ppBtn.addEventListener(MouseEvent.CLICK, ppState);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

Great - it works - thanks for your help. I just switched round the play and pause too.

Thanks

Alex

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

Which answer was helpful (correct) ?  Could you mark it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 12, 2012 Apr 12, 2012

Copy link to clipboard

Copied

Hakan

After Googling for hours I came across your post and downloaded your simple example 2state.

Absolutely spot on for my needs, nice & simple.

Have found many complex solutions, but none as straight forward as yours.

Have adapted it and pleasantly surprised it does not cause issues with external AS3 file already attached (to load mysql via php) as other solutions have.

I am a newbie to AS3 which is a minefield compared to AS2, great post.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

I just tried this and got a memory error. It worked fine the first time, and now it doesn't work any more?

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

here's my new issue. I restarted and got it to work, but now the timeline stops and doesn't start. I'm getting this in my output window:

ArgumentError: Error #2109: Frame label pauseButton not found in scene pauseButton.

          at flash.display::MovieClip/gotoAndStop()

          at myLibertyMobile_fla::MainTimeline/ppState()

ArgumentError: Error #2109: Frame label pauseButton not found in scene pauseButton.

          at flash.display::MovieClip/gotoAndStop()

          at myLibertyMobile_fla::MainTimeline/ppState()

ArgumentError: Error #2109: Frame label pauseButton not found in scene pauseButton.

          at flash.display::MovieClip/gotoAndStop()

          at myLibertyMobile_fla::MainTimeline/ppState()

ArgumentError: Error #2109: Frame label pauseButton not found in scene pauseButton.

          at flash.display::MovieClip/gotoAndStop()

          at myLibertyMobile_fla::MainTimeline/ppState()

and here's all the code I'm using:

var pp:Boolean = true;

function ppState(event:MouseEvent) {

if(pp) {

stop();

event.target.gotoAndStop('pauseButton');

pp = false;

}else{

play();

event.target.gotoAndStop('playButton');

pp = true;

}

}

ppBtn.addEventListener(MouseEvent.CLICK, ppState);

rewind.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame);

function fl_ClickToGoToAndPlayFromFrame(event:MouseEvent):void

{

          gotoAndPlay(1);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 22, 2012 May 22, 2012

Copy link to clipboard

Copied

ok, this is solved. There is something that was left out here... when I created my play and pause graphics, they came in as movie clips. They can't have a place for an instance name because for some reason the code looks for that.

Dave

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

a working sample:

http://www.flashdersi.com/flash/diger/adobeforum/2state.fla

with your unchanged codes...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 19, 2013 May 19, 2013

Copy link to clipboard

Copied

LATEST

Hi there, any chance you still have this working example? I am having a problem with my play/pause button and I'd love to see a solution that actually works!

Thank you in advnace!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines