6 Replies Latest reply on Apr 9, 2009 3:06 PM by dspeziale

    Play/Pause button

      I am using Flash CS3 and ActionScript 2.0.

       

      I have a flash timeline that shows 4 tabs and cycles through them. There is also a play/pause button. My issue is that when you click one of the tabs, you start the timeline up again, but the play/pause button doesn't reset.

      A look at the attached should help. I have the full Flash file, as well, if needed.
      http://www.danspeziale.com/flash/TabbedFlash10.swf

      http://www.danspeziale.com/flash/TabbedFlash10.fla

      I appreciate the help!
      Dan

        • 1. Re: Play/Pause button
          Dan.Smith Level 2

          Hi Dan,

           

          Put a stop(); on each of your keyframes where you have a tab.  That should do it.

          • 2. Re: Play/Pause button
            Level 1

            Dan, thanks for the help. Unfortunately, now when "play" is pressed, it goes to the next tab and stops. I would like it to spend 6 seconds (or so) on each tab, then go to the next one. However if pause is pressed, I'd like it to work as normal tabs, without cycling through.

             

            Thank you,

            Dan

            • 3. Re: Play/Pause button
              Ned Murphy Adobe Community Professional & MVP

              You'll probably need more logic built into the file to manage the options.  If the Pause button has been used, it could set a boolean variable (ex: playActive = false  Then, have the Play button set it to be true.  So when you get to each frame, you could have a conditional that utilizes this variable to see if it should wait awhile before proceeding (Play) or stay stopped (Pause).  You could use setTimeout for the delay.  So for each frame where you might currently have the stop();...

               

              stop();

              if(playActive){

                 setTimeout(playOn, 6000);

              }

               

              and you could have a shared function for the timeout function call...

               

              function playOn(){

                 play();

              }

              • 4. Re: Play/Pause button
                Level 1

                Hi Ned,

                 

                I appreciate your answer. I don't have direct experience with this type of code. Is there anyone that can point me to an actual working example or code? Thanks again for the prompt response.

                 

                Dan

                • 5. Re: Play/Pause button
                  Ned Murphy Adobe Community Professional & MVP

                  Here's a chance to get some experience then... That code is just short of being an actual working example that you can copy/paste in.

                   

                  If you don't already have one, create an actions layer that extends the full length of your timeline and copy the playOn function in the first frame of it.  In that same frame, add...

                   

                  var playActive = true; // this assumes the things starts in the play mode

                   

                  Then, in each frame where you put a stop (relative to Dan's suggestion), replace it with the rest of the code I provided (the stop(); and the if(){setTimeout} bit ).

                   

                  Then, for whatever code you already have for your play and pause buttons, add...

                   

                  playActive = false;  // in the pause button code

                   

                  playActive = true;   // in the play button code

                   

                  If you have any wonderings about the code, the Flash help documentation is a good reference.  But feel free to ask if you can't find it or understand it.

                  • 6. Re: Play/Pause button
                    Level 1

                    Thank you for bearing with me here. I think the code is working now!

                    NedWebs wrote:

                     

                    If you don't already have one, create an actions layer that extends the full length of your timeline and copy the playOn function in the first frame of it.  In that same frame, add...

                     

                    var playActive = true; // this assumes the things starts in the play mode

                    I've done this step above, adding an actions layer and adding the function:

                     

                    var playActive = true; // this assumes the things starts in the play mode

                    function playOn(){

                       play();

                    }

                    + the old code that was there:

                    var playState:Boolean=true;
                    btn_mc.onRollOver=function(){
                        this.gotoAndStop(2);
                    }
                    btn_mc.onRollOut=function(){
                        this.gotoAndStop(1);
                    }
                    btn_mc.onRelease=function(){
                        this.gotoAndStop(1);
                        if(playState){
                            playState=false;
                            this.btnTxt_mc.gotoAndStop(2);
                            this._parent.stop();
                        }else{
                            playState=true;
                            this.btnTxt_mc.gotoAndStop(1);
                            this._parent.play();
                        }
                    }

                     

                    This is the code I've used for the pause / play button toggle:

                     

                    The pause button:

                    playActive = false;  // in the pause button code

                     

                    The play button:

                    playActive = true;   // in the play button code

                     

                     

                    Again thanks to Dan and Ned for the help!

                    Dan