Pausing Sound Clips

By sgrosvenor
We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now

I’ve been contacted over the past few weeks on several occasions regarding the use of sound and the sound object within Flash, and strangely enough, the same question keeps on coming up; “How do I pause and then resume sound?

We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now
  • JesterXL

    Another way, since position stays the same when you stop a sound, is to just start and stop it:

    my_sound = new Sound(this);

    function onKeyDown()
    case Key.LEFT:
    my_sound.start(my_sound.position / 1000);

    case Key.RIGHT:

  • Aaron

    Awhile back I built a FlashMX-based MP3 player that streams MP3’s. I didn’t build in pause functionality because I didn’t see it used in streaming-based players online. However, I’ve started the process for implementing my player in AS2. Along with that upgrade I thought about putting in a pause button. I haven’t attempted it yet, but I think I did read somewhere that pausing streaming media wasn’t possible in Flash. I’ve written a few dozen components that have pause controls for event-based sounds so adding the code won’t be hard, but as yet I can’t say whether it will work or not.

  • SmeezuS

    I’ve tried this script in Flash MX 2004, tho I can seem to get it to work. Is there a special way to get it to work in MX 2004, or is it just not possible?

    [PS im relitavely new to Flash, tho am learning quick, so plz, not to complicated]

  • Jesse

    Just so people know, pausing is possible in new versions of the flash player using the stop() and start() methods. however, if you do this your sounds won’t play at all if the user has an older version — If anyone has ideas about how to check if this pausing works (or a list of the flash player versions that fail), please post them here.

  • eberline

    Streaming audio can be paused in Flash MX. All you have to do is create a movie clip, then within a layer of the movie clip (to do this, double click on your newly created movie clip), you simply load the movie in from your library. Make sure you Sync the audio to stream. Then return to your main stage, create the pause and play buttons. To pause:

    on(release) {;

    to play:

    on(release) {;

    note: the above code will pause flash audio, the flash timeline and an external swf. To only pause the flash audio, simply remove all lines of code that contain the word “_root”.

    variable explanation:

    host – Instance name of movie clip for external swf to load onto

    mymovie – Instance name of movie clip which audio loads into

    One final note about this. Streaming audio is the worst quality of audio flash offers. If you are making a demo I suggest that you use the code given at the top of this page and keep your audio sync as normal.

    Enjoy :).

    Thanks a lot for the code at the top of this page, it worked like a charm for me :).

  • bez

    i think people want to know how to pause the external .mp3, not another .swf.

  • ramos

    what about making the control a single button

  • Mathieu

    There’s one problem with your example, you can continuously push play to have alot of versions of the same unsynchronized mp3s playing at the same time.

    It would be practical for the play button to detect that the mp3 is playing and disallow overdubbing. If you have the scripting for this, I would really appreciate to view it.

    • EH

      Right, I know this thread has been left for quite a while, but just for the reference of google-ers, there is a solution to the problem Mathieu has highlighted…

      Go to the frame properties (window>properties) over which the sound is placed. Under the sound properties> sync selection select stream from the drop-down box. It should now only play one instance of that clip.

      • EH

        Oh yeah, provided you have flash cs5. Not sure how well it goes on other versions.

  • prakash sharma

    I have multiple movie clips with different sounds in each movie.

    My movie clips are placed across the main timeline of my movie.

    I have a “Next” and “Back” button on the main timeline that jumps me from frame to frame where each movie clip is placed. Everything works great…..but my sounds from the movie clips are running together.

    How do I stop all sounds in a movie clip from the main timeline when I click either the “Next” or “Back” button.

    I have a background sound on the main timeline and I do not want to stop this sound…….so the StopAllSounds function is not working for me. I just want to stop the sounds in the Movie Clip when I click the “Next” button.