A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11211 Flash Movies | 9 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Zeeshan Ozair
» Title: Lensflare
» Description: Probably one of the better lens flare effects available out there.
» More by Zeeshan Ozair


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 6567 Flash Sites | 4 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: ANDY FOULDS DESIGNi
» Comments: The Award-winning Flash Design Portfolio of Freelance Web Designer Andy Foulds


Random Links | Add your own Flash Related Links
Flash Tutorials 1170 Tutorials 7 New Tutorials Added!
What's New | Top100

» Create Graduation Photo Slideshow to Cherish School Memories
» Making movieclips point at the mouse
» Create Flash slideshow for Youtube
» Move a sprite with the keyboard
» Convert FLV to AVI video with DIVX codec to author a desired video with your favorite FLV movie!
» Flash Video Conversion Guide for Apple TV
» How to Convert FLV to iPhone movies
» Convert FLV(Flash Video) video to Cell Phone
» Convert FLV to AVI with XviD video codec to enjoy a DVD quality video with half of its size
» Unknown Tag: Title10
Random Tutorial | Add Site

bbm.netBBM.net is designed to save you time and deliver the highest quality royalty-free music for your multimedia projects. Features include: over 450 Music Loop Packages from some of the best composers in the business, our music search engine to speed your selection process, alternate music versions & bonus sounds to use for rollovers or transitions, free technical support and free consulting.

Click here for details »

Visual / UI Designer
Aquent
US-CA-San Francisco

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Audio

Categories 'Pause' a sound object
Author: marius hartmann | Website: http://www.xoz.net |

 
Page 1
1

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();
s.attachSound("jinglebells");
s.start();
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().
i=1;
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;
i++;
}

and after the s.start().
timeme();

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:
on(press){
s.stop();
timeme();
}


The second button for unpausing the sound should have the following actionscript.
on(press){
s.stop();
s.start(_root.newstarttime);
}

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!

1

» Level Advanced

Added: : 2002-03-23
Rating: 8.50 Votes: 120
Hits: 1152
» 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.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers