21 Replies Latest reply on May 9, 2009 5:30 PM by Ned Murphy

    (Flash) Stop and Play button (2 in 1)

    ruicosta99

      Hi. I have a doubt in a Flash animation that I'm doing. I want to put a Play and Pause button together. Let me explain better. I want that when the animation begin a Pause button appear, and when I click on that Pause button, the button switch to a Play button, that can be able to put the animation playing, when I click in it.

      I've already seen many tutorials on the Internet, but those tutorials that I've found doesn't match with what I'm looking for, because my animation has 1485 frames, and many groups with layers, so I can't put this buttons playing.

      PS: I don't understand nothing of Programing, so if you could help I would be greatful. By the way, sorry for my bad English.

      Thank you,

      Rui

        • 1. Re: (Flash) Stop and Play button (2 in 1)
          Ned Murphy Adobe Community Professional & MVP

          One way to approach this is to have the two buttons sit one on top of the other.  Initially you would have the play button invisible.  When you click the pause button, the pause button is commanded to turn invisible and the play button is commanded to become visible.  Likewise, when you click the play button it is turned invisible while the pause button becomes visible.  In order to do this the buttons need to have instance names.  Let's say you name them playBtn and pauseBtn...  In the first frame where they live in the timeline, on the actions layer, use the following...

           

          playBtn._visible = false;

           

          playBtn.onRelease = function(){

               playBtn._visible = false;

               pauseBtn._visible = true;

               this.play();

          }

           

          pausBtn.onRelease = function(){

               pauseBtn._visible = false;

               playBtn._visible = true;

               this.stop();

          }

          • 2. Re: (Flash) Stop and Play button (2 in 1)
            ruicosta99 Level 1

            Thank you by the answer. But my problem isn't solved yet. I've done exactly has you've said, but the buttons appear one on the top of the other, and when I click on them, they do nothing. By the way, both buttons are on the same layer, and converted to buttons, with the names you used in the example (playBtn and pauseBtn).

            • 3. Re: (Flash) Stop and Play button (2 in 1)
              Ned Murphy Adobe Community Professional & MVP

              First, in my code, if you copied it, the pauseBtn code is mis-spelled (missing the e).  Also, remove "this." from in front of play(); and stop();.

               

              Did you assign the instance names to the buttons or did you only name them with those names in the library?  Instance names are assigned in the Properties panel.

               

              Does to code for the button exist in the same frame (not necessarily the same layer) as where the buttons first appear?

              1 person found this helpful
              • 4. Re: (Flash) Stop and Play button (2 in 1)
                ruicosta99 Level 1

                I've done everything you've said, but it still doesn't work. But the animation had progress, now when I begin it only appears the Pause button, but when I click on it doesn't work.

                I haven't understood what you've said at last: "Does to code for the button exist in the same frame (not necessarily the same layer) as where the buttons first appear?", but, just for you to know, the Pause and Play button are in the same layer, one on the top of the other.

                Thank you,

                Rui

                • 5. Re: (Flash) Stop and Play button (2 in 1)
                  Ned Murphy Adobe Community Professional & MVP

                  I prepared an example file for you, but for some odd reason it won't download from my web site.  I am going to try to attach it here, though that requires I rename the file extension to something acceptable.  For the file I add here, you will have to rename it to have an "fla" extenstion instead of a "txt" extension.

                  1 person found this helpful
                  • 6. Re: (Flash) Stop and Play button (2 in 1)
                    ruicosta99 Level 1

                    It still didn't worked. I've copied the frames in the .fla file, but didn't worked. My 2 images (that were converted to buttons) have exactly the same name, I don't know where the problem is, it's really frustating. I'm sorry for being boring, but I really wanted to make this work.

                    Thank you,

                    Rui

                    • 7. Re: (Flash) Stop and Play button (2 in 1)
                      Ned Murphy Adobe Community Professional & MVP

                      Does the file I provided work?  It does for me.  What you need to do is study that file to see how the pieces are put together and they try to duplicate it in your own design.  Copying things is not likely to work if you don't have everything prepared properly.

                       

                      If you can attach your own attempt at this (a non-CS4 file) I can look at it and see what you might be missing.

                      • 8. Re: (Flash) Stop and Play button (2 in 1)
                        ruicosta99 Level 1

                        Yes, the file you send work perfectly. The problem is that I don't know nothing about Programing, and Codes. Do you have a Skype account? The file has 37mb, so I can't attach him here.

                        • 9. Re: (Flash) Stop and Play button (2 in 1)
                          Ned Murphy Adobe Community Professional & MVP

                          No, no Skype.  Just do your best to compare the two files, not just the code but the instances as well.  Whatever you are not doing correctly is most likely a simple mistake that can probably be rectified by understanding how my file works.

                          • 10. Re: (Flash) Stop and Play button (2 in 1)
                            Ned Murphy Adobe Community Professional & MVP

                            What you should do is create a new file to focus on resolving this.  Essentially recreate what I did, but without copying and pasting the frames.  Create a couple of buttons, give them instances names in the properties panel, and assign functions for those instances.

                             

                             

                            If you do this, and it doesn't work, then you will have something small that you can attach here (remembering the need to rename its extension).

                            • 11. Re: (Flash) Stop and Play button (2 in 1)
                              ruicosta99 Level 1

                              There it is the file,just to show you how I want the buttons (and still doesn't work).

                              • 12. Re: (Flash) Stop and Play button (2 in 1)
                                Ned Murphy Adobe Community Professional & MVP

                                As I mentioned earlier, I cannot open a CS4 file if that's what you have attached.

                                • 13. Re: (Flash) Stop and Play button (2 in 1)
                                  ruicosta99 Level 1

                                  Oh, sorry. I think that now the file is ok.

                                  • 14. Re: (Flash) Stop and Play button (2 in 1)
                                    Ned Murphy Adobe Community Professional & MVP

                                    As I said, copying and pasting won't work if you don't have everything in agreement.  If you change your pause button instance name (you named it stopBtn) to agree with the code (which uses pauseBtn) things should work.

                                    • 15. Re: (Flash) Stop and Play button (2 in 1)
                                      ruicosta99 Level 1

                                      I've done has you've said and it worked. Although, in the other animation I have the names correct, but it still doesn't work. I've done about 3 times since the beginning, but nothing.

                                      • 16. Re: (Flash) Stop and Play button (2 in 1)
                                        ruicosta99 Level 1

                                        I've made it, I created the button that I wanted. But of a bit strange way. I've searched on the Internet, and I've found one other solution... Create two movie clips, and put them the code

                                         

                                        on(press){
                                        this.gotoAndStop("pause");
                                        }

                                        on(release){
                                        this.gotoAndStop("play");
                                        }

                                         

                                         

                                        I've done this, created 2 movie clips, and put them the code to each one


                                        on(release){
                                        this.gotoAndStop("play");
                                        }

                                         

                                        to the play button, and

                                         

                                        on(press){
                                        this.gotoAndStop("pause");
                                        }

                                         

                                        to the pause button. I've done Preview, and I got surprised. When I clicked on your Pause button... the Play button from the movie clip appeared.

                                        So, now I have the Pause button, and the Play movie clip, and it's working!

                                         

                                        Thank you for all the help you gave me, and for the time you lost answering.

                                        Rui

                                        • 17. Re: (Flash) Stop and Play button (2 in 1)
                                          Ned Murphy Adobe Community Professional & MVP

                                          I'm not really sure what you have working for you now, but you're welcome.  All you needed to do to fix it was rename your pause button instance to agree with the code.

                                          • 18. Re: (Flash) Stop and Play button (2 in 1)
                                            ruicosta99 Level 1

                                            In my animation the code was correct, the name on the button was the same that in the code.

                                            Thank you,

                                            Rui.

                                             

                                            I hope that this question can help other persons solving the same problem I had.

                                            • 19. Re: (Flash) Stop and Play button (2 in 1)
                                              Ned Murphy Adobe Community Professional & MVP

                                              The code was correct, but the instance name was not the same as what the code used in the sample file you provided, but if you choose to believe so, you don't understand what instance names are.  I've included a screenshot to show you the file you provided, with the mismatched parts identified by red markings.

                                               

                                              pausestop.gif

                                               

                                              So if you had simply named the button correctly (where it is circled in red), it would have agreed with the code and worked.

                                               

                                              The code you apparently followed up using, while not a recommended design approach (discontinued as an option in AS3), will work because it doesn't not require instance names.

                                              • 20. Re: (Flash) Stop and Play button (2 in 1)
                                                ruicosta99 Level 1

                                                Yes, you've told me that, and when I've changed the name of the button to pauseBtn it worked, you were right. But in the other animation, the "real" one, those names were exactly the same, I can guarantee that to you, but it didn't worked, I don't know why (I don't know almost nothing about programing, as I've said before). I even changed the name of the buttons, and also of the code to pauseBtn99 (both of them) and names like that.

                                                But I think that I have made some mistake, because in the other testing animations I've done with your code they all worked.

                                                I'm sorry for taking your time, once more, and thank you a lot.

                                                Rui