A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Pause/Play Toggle Button?

  1. #1
    Member
    Join Date
    Feb 2005
    Posts
    32

    Pause/Play Toggle Button?

    I have an AIF file I created in Garage Band. This AIF has been placed into a movie clip called "mymusic" that has been placed on a layer in my movie with an instance name of "mymusic."

    I have created play button and pause buttons that utilize the following scripts to stop the sound and the movie and then resume the sound and movie from the point where it was stopped:


    Play Button:

    on (press) {
    play();
    tellTarget ("mymusic") {
    play () ;
    }
    }


    Stop Button:

    on (press) {
    stop();
    tellTarget ("mymusic") {
    stop () ;
    }
    }


    This works perfectly. Now the client wants me to combine the play and pause button and create a single toggle button that achieves what the above two described buttons did.

    Any thoughts? Please help!!!

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    put this on your _root timeline:

    Code:
    var musicPaused:Boolean = true;
    and then your button press should be:

    Code:
    on (press) {
    if(!_root.musicPaused){
    	 stop();
    	_root.musicPaused = true;
    	tellTarget ("mymusic") {stop ();}
    }else{
    	play();
    	_root.musicPaused = false;
    	tellTarget ("mymusic") {play ();}
      }
    }
    P.S why are you using tellTarget? that has been deprecated a long time ago... u should use dot notation instead
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    Feb 2005
    Posts
    32
    Silentweed,

    Thanks for the help. It doens't appear to be working though. My button still changes from the play to the pause icon and the music stops, but when I press the button again the music won't restart.

    Any thoughts? I can attach the movie if you want.

    Oh, and I'm using the yell Target script because I'm pretty much a Flash novice. Any better suggestions?

    Thanks again!

  4. #4
    Member
    Join Date
    Feb 2005
    Posts
    32
    I've been playing with the script a little and had added this to it:

    on (press, release) {
    if (!_root.musicPaused) {
    stop();
    _root.musicPaused = true;
    tellTarget ("mymusic") {stop ();}
    } else {
    play();
    _root.musicPaused = false;
    tellTarget ("mymusic") {play ();}
    }
    }


    on (release) {
    if (_root.stop == 1) {
    tellTarget (stop_play) {
    gotoAndPlay(2);
    }
    } else {
    //_root.play();
    tellTarget ("mymusic") {
    stop () ;
    }tellTarget (stop_play) {
    gotoAndPlay(1);
    }

    }
    }


    When I click the button the music will stop and the button state will change from pause to stop. However, only when I click and hold will the music resume playing. Also, if I completely eliminate the button swap portion of the script, the pause will work, but it only works the second time I click the button. The first click (even if I click and hold) will only cause the music to pause for half a second and then it resumes playing.

    Any thoughts?

    Thanks!

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    hi, yeah it will be easier to understand if you upload your fla
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Member
    Join Date
    Feb 2005
    Posts
    32
    Hey. I got it!

    I had two extra lines of script in there that were messing it up and then I commented-out the "Boolean" script and that took care of it. Weird. Any thoughts on that? I wonder if it was conflicting with the antiquated "tellTarget" script.

    Thank God I can design, because I'm not much of a programmer.

    Thanks so much for your help!

    Best of luck!

  7. #7
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Specify you flash version. Maybe it's not 8... ?

    gparis

  8. #8
    Member
    Join Date
    Feb 2005
    Posts
    32
    Flash 8

  9. #9
    Senior Member
    Join Date
    Nov 2005
    Location
    dante's inferno
    Posts
    904
    the file is probably not set to support actionscript 2.0 in the publish properties to support:

    var musicPaused:Boolean = true;

  10. #10
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    That whole script was written a long time ago, using at best Flash5. Or by someone who hasn't touched AS for years....



    gparis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center