In this tutorial, you're going to learn how to pause sound objects in flash and make the sound/music resume exactly from where it was paused.
Note: This tutorial is much shorter than it seems, extra explanation is provided for your own benefit.
There are two ways to do this in flash:
The complicated way:
Using the "Get time" action to calculate the total duration of your sound object, measuring the elapsed time and making the sound object resume next time based on the calculated previous elapsed time. It involves complicated action scripting, which would make this tutorial listed in the "Advanced" category instead. Morover, the result is not always perfect, you can't get a 100% precision when it comes to resuming the sound object from where it was left out.
The easy way:
By setting your sound object to "streaming" and using a couple of simple action
scripts to start and pause your sound, 100% precision. And that's what we're
going to do in this tutorial. :)
By using "Streaming" sound, it means we are going to spread the music over
the timeline of flash. We will place the object into a movie clip and it will
be played normally like any flash animation once the "play" button is pressed.
Pausing the movie clip in which the object resides will also result in pausing
the sound object. We can resume that by using the "play" action again.
Let's get started!
1:
Next, we're going to create a Movie Clip in which our sound object will be placed.
2:
Once you create your new symbol, you will be taken to it and you will notice Layer 1.
Now we're going to import our sound to flash.
3:
Good :) your sound object is now in the Library of Flash, you can check if you want, go to Windows>Library (or press F11).
4:
Ok, now we're going to "spread" our sound/music over the timeline.
Depending on the length of your sound, right-click a keyframe on the timeline
and select "Insert Keyframe".
Notice Fig 5, my music almost ends by the 190th keyframe. what we want is having
the whole sound clip be played in flash, so we have to make sure we don't "insert
keyframe" before the sound/music ends.
Go back to the first frame, righ-click it and select Actions.
Add a stop (); action to it.
The reason why we left that single keframe and added a stop action to it is
because we don't want flash to play our music once the file is loaded, we want
to control it and play it only when the "play" button is pressed.
5:
That's what your timeline should look like.
Only 3 more steps are left and you're going to be able to pause your music in flash :)
6:
Ok that looks good. We're back to the main stage, now we're going to place our Movie Clip that holds our music on the stage.
7:
Now we're going to add an "Instance Name" to our movie clip, this name will be used as a target to play and pause the movie clip.
Good work, the following page is the last one, we're going to add actions to buttons.
8:
In this step, we're going to add 2 buttons to the "buttons" layer.


Add the following action to the "pause" button:
you're done! good job, now test your movie. :)
Conclusion:
What we did:
A 100% precision, with minor action scripting. Hope you enjoyed this tutorial.
Download *.fla