First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: marius hartmann | Website:
So you want to use a sound object for your flash movie.. and give the user the ability to pause your sound instead of just stopping it and then starting it from the beginning?

First of all - import a sound - via rightclicking on the sound in the library - choose 'linkage'.

Choose to 'export this symbol', and give it a name you will be able to identify it by - in this case 'jinglebells'.

On the movies first keyframe we will instantiate a sound object, attach your sound to that object, and tell the sound to play.
here goes:
s = new Sound();
Now that didn't hurt one bit! If you test your movie now - you should have music playing.

Plz. notice that we have not put the sound in any frame - we have simply 'glued' it to an invisible object.

Now for the hairy part.
We want the music to continue playing from the position we pressed pause - so we have to time our sound.
For this we will use the good old Date() object and place it in a function for easy access.
In the first keyframe continue the script by inserting the following before s.start().

function timeme (){
now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();

_root["nowtime"+i] = (Number(hours)*3600)+(Number(minutes)*60)+seconds;

_root.newstarttime = _root["nowtime"+i] - _root.nowtime1;


and after the s.start().

Now that was a strange brew - but in short the script times when we started the sound (nowtime1) and compares it to when we stopped the sound (nowtime+i). That info is converted to seconds, and is fed into our start button later.

Next make 2 buttons - one for pausing the sound, and one for un-pausing it.
The first button should have the following actionscript:

The second button for unpausing the sound should have the following actionscript.

The thing that makes this work is the variable 'newstarttime' it is fed into the un-pause button and is used for the built in 'secondsOffset' method which starts the sound x-seconds into the sound.

If you are experiencing trouble try importing another sound into your library.

Good luck!
» Level Advanced

Added: 2002-03-23
Rating: 7.8 Votes: 140
(10 being the highest)
» Author
Marius Hartmann is a danish artist, currently writing a Ph.d-project on 'visualization of dynamic information'.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.