23 Replies Latest reply on Nov 10, 2010 10:22 PM by kglad

    Play/Pause slide show

    988hfas9fhaf8 Level 1

      I have a simple slide show with a forward & backward button, as well as a play & pause button.

      The play/pause buttons toggle visability with this code (on its own actionscript layer):

       

       

      //FIRST HIDE THE PLAY BUTTON
      playBtn._visible = false;

       


      //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
      pauseBtn.onRelease = function() {
          ns.pause(true);
          playBtn._visible = true;
          pauseBtn._visible = false;
      };


      //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON

      playBtn.onRelease = function() {
           ns.pause(false);
           playBtn._visible = false;
           pauseBtn._visible = true;
      };

       

       

      All is well. However, the problem is that when someone pauses the slideshow and just moves through the images with the forward/backward buttons, the play button disappears when it gets back to the first image. I think it might because of the first line that says to hide the play button, but I don't see how.

       

      One thing I tried was to add this bit of code to say that if the net stream is paused, always show the play button. If it is playing, always show the pause button:

       

      if     (ns.pause(true)) {

               playBtn._visible = true;

               pauseBtn._visible = false;

       

      } else {

               playBtn._visible = false;

               pauseBtn._visible = true;

      }

       

      However, this didn't work - at least not the way I wanted. This code causes the pause button to show up when you cycle through the images and get back to frame one - somehow forcing the net stream to play again.

       

      Can anyone tell by my code why that would happen? I'd at least like to know how to show the pause button whilst it's playing and vice-versa for the play button.

      There's nothing on the timeline that would obstruct the buttons from the end of the timeline to the beginning. I think it's in the code, but I can't see it.

        • 1. Re: Play/Pause slide show
          kglad Adobe Community Professional & MVP

          what's the netstream instance have to  with this?  and, where or what is controlling the slideshow?  (you're not using a netstream instance to display a slideshow, are you?)

          • 2. Re: Play/Pause slide show
            988hfas9fhaf8 Level 1

            The images are all running along the timeline, moving over at various points.

             

            From what I've seen, .ns seems to start and stop the movie from playing. I figured it works, why mess with it. Does that have something to do with my issue?

            • 3. Re: Play/Pause slide show
              kglad Adobe Community Professional & MVP

              yes.  remove you netstream/netconnection code.

               

              use the movieclip play(), stop() and goto methods to control your main timeline.

              • 4. Re: Play/Pause slide show
                988hfas9fhaf8 Level 1

                I wanted to control the whole movie with the play/pause since that's the only thing it does. I'm not sure how do keep those actions with play and stop.

                 

                Maybe this?

                 

                 

                playBtn._visible = false;



                //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                playBtn.onRelease = function() {
                     _root.stop();
                     playBtn._visible = true;
                     pauseBtn._visible = false;
                };



                //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                pauseBtn.onRelease = function() {
                     _root.play();
                     playBtn._visible = true;
                     pauseBtn._visible = false;
                };

                • 5. Re: Play/Pause slide show
                  kglad Adobe Community Professional & MVP

                  when you swf first starts so you want you main timeline to be playing or to be stopped?

                  • 6. Re: Play/Pause slide show
                    988hfas9fhaf8 Level 1

                    It will be moving when it starts, stopped when the pause button is released.

                    • 7. Re: Play/Pause slide show
                      kglad Adobe Community Professional & MVP

                      is there any problem with the last code snippet you showed?

                      • 8. Re: Play/Pause slide show
                        988hfas9fhaf8 Level 1

                        It doesn't produce or report any errors, if that's what you mean.


                        • 9. Re: Play/Pause slide show
                          kglad Adobe Community Professional & MVP

                          does it do what you expect?

                          • 10. Re: Play/Pause slide show
                            988hfas9fhaf8 Level 1

                            I've altered it so it now shows the pause button when the slide show cycles through to the beginning again. I'd rather it show the play button, but for some reason it doesn't do that.

                             

                            Here's the revised code:

                             

                            //BOTH BUTTONS ARE ON THE STAGE, SO FIRST HIDE THE PLAY BUTTON (SINCE IT STARTS PLAYING AUTOMATICALLY)
                            playBtn._visible = false;

                             


                            //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                            playBtn.onRelease = function() {
                                ns.pause(false);
                                playBtn._visible = true;
                                pauseBtn._visible = false;
                            };

                             


                            //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                            pauseBtn.onRelease = function() {
                                ns.pause(true);
                                playBtn._visible = true;
                                pauseBtn._visible = false;
                            };

                             


                            if     (ns.pause(true)){
                                playBtn._visible = true;
                                pauseBtn._visible = false;

                             

                            } else {
                                playBtn._visible = false;
                                pauseBtn._visible = true;
                            }

                            • 11. Re: Play/Pause slide show
                              kglad Adobe Community Professional & MVP

                              you're going backwards with your code when you use netstream incorrectly.

                              • 12. Re: Play/Pause slide show
                                988hfas9fhaf8 Level 1

                                Please elaborate?


                                • 13. Re: Play/Pause slide show
                                  kglad Adobe Community Professional & MVP

                                  yes.  remove you netstream/netconnection code.

                                   

                                  use the movieclip play(), stop() and goto methods to control your main timeline.

                                  • 14. Re: Play/Pause slide show
                                    988hfas9fhaf8 Level 1

                                    Maybe this?

                                     

                                     

                                    playBtn._visible = false;



                                    //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                                    playBtn.onRelease = function() {
                                         _root.stop();
                                         playBtn._visible = true;
                                         pauseBtn._visible = false;
                                    };



                                    //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                                    pauseBtn.onRelease = function() {
                                         _root.play();
                                         playBtn._visible = true;
                                         pauseBtn._visible = false;
                                    };

                                    • 15. Re: Play/Pause slide show
                                      kglad Adobe Community Professional & MVP

                                      you probably want:

                                       


                                       

                                      playBtn._visible = false;



                                      //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                                      playBtn.onRelease = function() {
                                           _root.play();
                                           playBtn._visible = true;
                                           pauseBtn._visible = false;
                                      };



                                      //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                                      pauseBtn.onRelease = function() {
                                           _root.stop();
                                           playBtn._visible = true;
                                           pauseBtn._visible = false;
                                      };

                                      • 16. Re: Play/Pause slide show
                                        988hfas9fhaf8 Level 1

                                        I remember trying that before. When the movie first starts, it's fine. However, pressing the pause button with this code will disarm the play / pause button. In other words, the toggling option will no longer be there. The play button is visible (from pressing the pause) but it doesn't do anything after that.

                                         

                                        If anyone cares to look at it, I've uploaded it to a free site for files: http://drop.io/bcnfefa

                                        • 17. Re: Play/Pause slide show
                                          kglad Adobe Community Professional & MVP

                                          the play and pause buttons should be in their own layer, that layer should have only one keyframe and that layer needs to extend the entire length of your timeline.  after you fix that your buttons will continue to work and you can actually change some of the above restrictions.

                                          • 18. Re: Play/Pause slide show
                                            988hfas9fhaf8 Level 1

                                            Thanks for that.

                                             

                                            I did place the buttons on their own layer, then changed the .ns statements to simple  but that didn't do anything.

                                             

                                            So then I tried to add an if/else statement to keep at least one of the buttons there:

                                             

                                             

                                            if     (_root.stop(true)){
                                                playBtn._visible = true;
                                                pauseBtn._visible = false;

                                             

                                            } else {
                                                playBtn._visible = false;
                                                pauseBtn._visible = true;
                                            }

                                             

                                             

                                            But that just shows the pause button again, even though it was paused the entire time. Quite frustrating...

                                             

                                            To put things into perspective, the full code is this:

                                             

                                            //Both buttons are on the stage, so first hide the play button
                                            playBtn._visible = false;

                                             

                                             

                                             

                                            //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                                            pauseBtn.onRelease = function() {
                                                 _root.stop();
                                                 playBtn._visible = true;
                                                 pauseBtn._visible = false;
                                            };

                                             

                                             

                                             

                                            //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                                            playBtn.onRelease = function() {
                                                 _root.play();
                                                 playBtn._visible = true;
                                                 pauseBtn._visible = false;
                                            };

                                             

                                             

                                             


                                            if     (_root.stop(true)){
                                                playBtn._visible = true;
                                                pauseBtn._visible = false;

                                             

                                            } else {
                                                playBtn._visible = false;
                                                pauseBtn._visible = true;
                                            }

                                            • 19. Re: Play/Pause slide show
                                              kglad Adobe Community Professional & MVP

                                              just use:

                                               

                                              playBtn._visible = false;



                                              //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                                              playBtn.onRelease = function() {
                                                   _root.play();
                                                   playBtn._visible = true;
                                                   pauseBtn._visible = false;
                                              };



                                              //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                                              pauseBtn.onRelease = function() {
                                                   _root.stop();
                                                   playBtn._visible = true;
                                                   pauseBtn._visible = false;
                                              };

                                              • 20. Re: Play/Pause slide show
                                                988hfas9fhaf8 Level 1

                                                That's what I was talking about in the first part of my last response. The play button disappears when I do that.

                                                 

                                                The pause button is on its own layer. The play button is on its own layer. There is nothing disrupting them throughout the whole timeline. The actionscript code isn't disrupted either. I'm lost.

                                                • 21. Re: Play/Pause slide show
                                                  kglad Adobe Community Professional & MVP

                                                  that's what you wanted.  you said your app would start with the timeline playing so you wanted your play button to be invisible.  the pause button is visible.  when the pause button is clicked, the timeline stops, the play button is visible and the pause button is invisible.  when the play button is clicked, the timeline plays, the pause button is visible and the play button is invisible.

                                                  • 22. Re: Play/Pause slide show
                                                    988hfas9fhaf8 Level 1

                                                    That is true. However, the pause button and the play button disappear when the timeline gets to the beginning again. That is the original problem. I don't see where in the code that it's telling the movie to get rid of the play button, yet it does.

                                                    • 23. Re: Play/Pause slide show
                                                      kglad Adobe Community Professional & MVP

                                                      that code should only execute once:

                                                       

                                                      var alreadyExecuted:Boolean

                                                       

                                                      if(!alreadyExecuted){

                                                      alreadyExecuted=true;

                                                      playBtn._visible = false;



                                                      //WHEN THE PAUSE BUTTON IS CLICKED, STOP THE MOVIE, HIDE THE PAUSE BUTTON, AND SHOW THE PLAY BUTTON
                                                      playBtn.onRelease = function() {
                                                           _root.play();
                                                           playBtn._visible = true;
                                                           pauseBtn._visible = false;
                                                      };



                                                      //WHEN THE PLAY BUTTON IS CLICKED, RE-START THE MOVIE, HIDE THE PLAY BUTTON, AND SHOW THE PAUSE BUTTON
                                                      pauseBtn.onRelease = function() {
                                                           _root.stop();
                                                           playBtn._visible = true;
                                                           pauseBtn._visible = false;
                                                      };

                                                      }