12 Replies Latest reply on Mar 23, 2010 3:09 AM by CCBrown

    Creating a pause button

    CCBrown

      I don't use Flash that much so the question may sound simple, but how do I pause audio in a timeline?  I have added the audio, play and stop button.  When I test it works fine, but I can't figure out how to add the pause button, or the play/pause button.

       

      Here is the link to the working file.

       

      Thanks.

        • 1. Re: Creating a pause button
          Ned Murphy Adobe Community Professional & MVP

          Change your code as follows, and remove the sound from the timeline.  Your code is attaching it from the library, but it needs to use the correct linkage name as I show below...

           

          var song_sound:Sound = new Sound();
          song_sound.attachSound("korean_war_final");

           

          var pausedAt = 0;

           

          play_btn.onRelease = function() {
              song_sound.start(pausedAt);
          };

           

          stop_btn.onRelease = function() {
              song_sound.stop();
          };

           

          pause_btn.onRelease = function() {
              pausedAt = song_sound.position/1000; // convert msec to sec
             song_sound.stop();
          };

          • 2. Re: Creating a pause button
            kglad Adobe Community Professional & MVP

            set your sound to stream (in the properties panel) and apply stop() to your timeline when you want the sound to pause.  apply play() to your timeline when you want the sound to play.

             

            or, even better, use the flash sound class to control your sound.

            • 3. Re: Creating a pause button
              CCBrown Level 1

              Ned, thanks for the reply.  I was out of town so I couldn't answer.  Yes, what you sent me work just as you said.  Is it possible to have the audio play when the scene is loaded?

              • 4. Re: Creating a pause button
                Ned Murphy Adobe Community Professional & MVP

                Just call the start method after you attach the sound...

                 

                song_sound.start();

                • 5. Re: Creating a pause button
                  CCBrown Level 1

                  Before I tried that, I decided to see if I could get my movie working properly.  I created a blank document with just the button and sounds and everything worked fine.

                   

                  But when I tried that approach within the movie, I get an error message.

                   

                  When I click on my first rollover button I am taken to the scene titled "Korean War," but the play button doesn't work.  When I check my AS it appears to be identical to the script in the sound.fla file, but of course I did something wrong.

                   

                  Craig

                  • 6. Re: Creating a pause button
                    Ned Murphy Adobe Community Professional & MVP

                    Looking at your  within the movie file, you have attached code to the play button that should be in the timeline instead.  When you attach code to objects (poor practice) it should involve some form of "on" code (on(release), onClipEvent(), etc).  Timeline code goes in the timeline by selecting the frame in the timeline and entering the code in the actions panel... just like the stop(); you have in the top layer of the first scene.

                    • 7. Re: Creating a pause button
                      CCBrown Level 1

                      Ned, first, thanks again for your time.  I haven't used Flash since I took three classes in 2004/05, and was thrown into a project.

                       

                      After your last reply it came back to me somewhat.  So I created another frame so I could put the audio code in the timeline.  When I preview no errors are compiled.  But when I add the play button in the Audio Controls layer I still get the error.  All I did was add the play button and give it the instance name "play_btn" to correspond with the script.

                       

                      http://www.ccbwebdesigns.com/Flash/NorthKorea_FLASH_V10.fla

                       

                      Thanks again.

                      • 8. Re: Creating a pause button
                        Ned Murphy Adobe Community Professional & MVP

                        While I am not going thru the history of this posting, based on my last reply to you, you haven't done anything to address what I said you were doing wrong the last time.  If you click on your play button you will see a bunch of code.  That code is attached to the button.  That code should not be attached to the button... it should be in the timeline where your stop(); command is.  Attached code needs to be inside on()-type handlers... and using on()-type handlers is bad practice.  Maybe you just need to go back to where this posting started and reread what I've offered.

                        • 9. Re: Creating a pause button
                          CCBrown Level 1

                          Re-read the post and think I figured out exactly what you meant.  I went into the button, deleted all Actionscript and deleted the various button states.  So now the button symbol contains only the graphic.  When I test the movie no errors are compiled, but I did give the button the action to goto frame 2 of the scene on release (so the audio will play).  The result is nothing.  Hopefully this is my last obstacle.

                           

                          Thanks Ned for your help.

                          • 10. Re: Creating a pause button
                            Ned Murphy Adobe Community Professional & MVP

                            If you deleted the code entirely, that isn't what you wanted to do.  You just needed to move it from being attached to the button to being placed in the timeline.  I don't know why you did anything to alter the button.

                            • 11. Re: Creating a pause button
                              CCBrown Level 1

                              OK, since apparently I can't wrap my brain around my problem, I started from scratch.

                               

                              I have the "Main" scene working fine.  The first two rollover button take me to their respective scenes.

                               

                              In the "Korean War" scene, the buttons work and the audio plays fine.

                               

                              I then copied the "Korean War" scene and named it "Weapons Development."

                               

                              I then when into the script and changed the audio from "korean_war_final" to "weapons_development."

                               

                              I made sure that my script in "Weapons Development" was exactly the same as 'Korean War," with the exception of the audio.

                               

                              When I select the play button in Weapons Development, I am taken back to the Korean War scene.  My guess is that there is something wrong with the button name, but I am not sure.

                               

                              Craig

                              • 12. Re: Creating a pause button
                                CCBrown Level 1

                                Ned,

                                 

                                Thanks for all your help.  I re-read all your post and found my old course material and realizeD my errors.  I was trying to associate different audio files with the same play button.

                                 

                                Thanks for all your patience.

                                 

                                http://ccbwebdesigns.com/Flash/NorthKorea_FLASH_V11.fla