# The very very basic of adding sound - heellpp!

**URL:** <https://forum.kirupa.com/t/the-very-very-basic-of-adding-sound-heellpp/2426>\
**Category:** Uncategorized\
**Created:** [April 4, 2002, 5:06am UTC](https://forum.kirupa.com/t/the-very-very-basic-of-adding-sound-heellpp/2426 "2002-04-04T05:06:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2002, 5:06am UTC](https://forum.kirupa.com/t/the-very-very-basic-of-adding-sound-heellpp/2426/1 "2002-04-04T05:06:46Z")

</div>

hi again.

I am trying to create a movie with a song playing in the background with 3 buttons - one to play, pause and to continue.

I found a tutorial in the [flashkit.com](http://flashkit.com) website but am having trouble understanding it. My questions are in brackets \< \>

Thanks you so much for helping.

* * *

Here goes:

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();

\< first question: where do i paste this code? right click, action…then where?\>

Now that didn’t hurt one bit! If you test your movie now - you should have music playing.

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();

\< again…where do i paste this code? \>

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();  
}

\< err…where do i paste this code? \>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [April 4, 2002, 7:59pm UTC](https://forum.kirupa.com/t/the-very-very-basic-of-adding-sound-heellpp/2426/2 "2002-04-04T19:59:11Z")

</div>

\< first question:  
“…On the movies first keyframe…”

\< again…where do i paste this code?  
"…In the first keyframe continue the script by inserting the following before s.start(). "

\< err…where do i paste this code? \>  
select the buttonon the scene, right click, actions, paste

Everything is IN the tutorial!
