# Pause and Mute for music?

**URL:** <https://forum.kirupa.com/t/pause-and-mute-for-music/22197>\
**Category:** flash\
**Created:** [May 31, 2003, 9:16pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197 "2003-05-31T21:16:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![JK87](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@JK87](https://forum.kirupa.com/u/JK87)\
**Post date:** [May 31, 2003, 9:16pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/1 "2003-05-31T21:16:17Z")

</div>

I have followed the Music Player and Volume Controller tutorials and as a result, can now play, stop and adjust the volume of a music file that is defined in the code. My apologies in advance if the questions below have been answered in the past.

However, I have searched the forums and can’t seem to find anything directly answering the two following questions:

i) What code would be required (I would assume code would only be required for the button used for pausing) for a button to pause the music playing when pressed?

ii) What code would be required (I would assume code would only be required for the button used for muting) for a button to mute the music playing when pressed?

Thanks for any and all help,  
JK.

---

<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:** [June 1, 2003, 12:07am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/2 "2003-06-01T00:07:04Z")

</div>

```auto
Sound.prototype.pause = function() {
	this.paused ? this.start(this.position/1000) : this.stop();
	this.paused = !this.paused;
};
Sound.prototype.mute = function() {
	if (this.muted) this.setVolume(this.volume);
	else this.volume=this.getVolume(), this.setVolume(0);
	this.muted = !this.muted;
};

```

example:

```auto
mySound = new Sound(this);
mySound.attachSound("sound");
mySound.start();
pauseButton.onRelease = function() {
mySound.pause();
};
muteButton.onRelease = function() {
mySound.mute();
};

```

😉

---

<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:** [June 1, 2003, 9:47am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/3 "2003-06-01T09:47:22Z")

</div>

I’ll check that out asap. Thanks sooooo much!!! :beam: :).

---

<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:** [June 1, 2003, 12:42pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/4 "2003-06-01T12:42:42Z")

</div>

Hi JK87 how are you  
I have also got the same problem with you,  
after reading this I still don’t understand

if you know how to do it, could you please tell me  
it will be perfect if you can attach a FLA as a example  
thank you

---

<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:** [June 1, 2003, 12:44pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/5 "2003-06-01T12:44:05Z")

</div>

I’m fine thanks. I haven’t had the opportunity to test this out yet because I have been trying to help SBV in another thread. Give me a few minutes and I will see what I can come up with :).

JK.

---

<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:** [June 1, 2003, 1:15pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/6 "2003-06-01T13:15:34Z")

</div>

Well, it’s certainly not trivial. Following the soundbar tutorials, you end up with a soundbar with which you can Play, Stop and Adjust the volume of a piece of music.

The Play button has this code applied to it:  
[AS]on (release) {  
if (\_root.mySlider.complete == 1) {  
\_root.mySlider.mySound.start(0, 99);  
}  
}[/AS]

The Stop button has this code applied to it:  
[AS]on (release) {  
\_root.mySlider.mySound.stop();  
}[/AS]

But the majority of the code resides in the slider which you use to adjust the volume.

If you follow what kax said, I think you need to do two separate things to get the Pause and Mute functions working. I may not be able to get it to work but I will do my best, give me a few more minutes please :).

_Note that I’m relatively new to Flash (less than a week), so I am hardly a coding expert._

---

<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:** [June 1, 2003, 1:26pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/7 "2003-06-01T13:26:45Z")

</div>

No luck, sorry. I can roughly see what you need to do but I don’t know exactly how to do it. Hopefully somebody will be able to clarify this for us :).

My apologies,  
JK.

---

<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:** [June 1, 2003, 1:29pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/8 "2003-06-01T13:29:24Z")

</div>

thank you very much for trying to do that for me 🙂

---

<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:** [June 1, 2003, 1:33pm UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/9 "2003-06-01T13:33:15Z")

</div>

No problems. Only next time, I would like to be able to solve the problem as well :).

It’s really frustrating because I can see what you need to change in the code to suit your file but I can’t work out exactly where the code would need to go :-.

---

<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:** [June 2, 2003, 5:29am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/10 "2003-06-02T05:29:59Z")

</div>

- jk87

use this script in your buttons to pause/mute the sound:

```auto
// pause
on (release) {
_root.mySlider.mySound.pause();
}
// mute
on (release) {
_root.mySlider.mySound.mute();
}

```

and instead of this script…

```auto
on (release) {
if (_root.mySlider.complete == 1) {
_root.mySlider.mySound.start(0, 99);
}
}

```

use this…

```auto
on (release) {
if (_root.mySlider.complete == 1) {
_root.mySlider.mySound.start();
_root.mySlider.mySound.onSoundComplete = function() {
this.start();
};
}
}

```

that should do it… 😉

- open0102

i don’t know how is your set up so i can’t really help you. could you attach your .fla? :-\

---

<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:** [June 2, 2003, 6:29am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/11 "2003-06-02T06:29:55Z")

</div>

Hi Kax, I really want to show you my fla file, but the file is too big to send on this sever.  
but if you really kind enough to help me, I have created a fla file that have Play, Pause, Stop and Mute buttons in it, there is no code in it, because I assume that it would be easier for you to work on, as I may make a lot of mistakes and you have to modify them. it will be gratefull if you can make it work.  
My apologies first if this is not a good way to ask  
thank you

---

<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:** [June 2, 2003, 6:34am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/12 "2003-06-02T06:34:33Z")

</div>

I am sorry why there is no option for me to attach the file

---

<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:** [June 2, 2003, 6:39am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/13 "2003-06-02T06:39:08Z")

</div>

to attach a file you must use the reply form (or whatever i should call it :P). 😉

\<a href=“newreply.php?s=&action=newreply&threadid=24787”\>  
\<img alt=“post reply button large” src=“images/post\_reply.gif” border=“0” width=“90” height=“25”\>\</a\>

---

<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:** [June 2, 2003, 8:14am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/14 "2003-06-02T08:14:38Z")

</div>

Thanks sooooo much kax (again :)) :thumb:.

---

<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:** [June 2, 2003, 8:44am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/15 "2003-06-02T08:44:56Z")

</div>

no problem. =)

---

<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:** [June 2, 2003, 9:32am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/16 "2003-06-02T09:32:01Z")

</div>

Haha go figure - neither of those work. The new play ActionScript works because it doesn’t actually change the function it just enhances it… but the ActionScript for pause and mute doesn’t work.

I think the mute could be done by using setVolume(0) when the user clicks the mute button but there is a problem with that in this case because the volume slider has mySound coded ‘inside’ it as such.

I looked in the help file of Flash MX and it doesn’t have .mute or .pause in the commands concerning sound :(. Perhaps you have to code both functions?

… either way, this has helped me improve my coding knowledge. Shame it doesn’t work though ;).

---

<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:** [June 2, 2003, 9:41am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/17 "2003-06-02T09:41:56Z")

</div>

ok… here’s an example.

put an .mp3 file called sound.mp3 in the same directory than the .fla to test it. 😉 =)

---

<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:** [June 2, 2003, 9:59am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/18 "2003-06-02T09:59:17Z")

</div>

Ahh… all your code was in the frame - not in the different buttons. That makes the first code you posted much easier to understand now lol.

It’s all working fine so I will toy around with it and see what I can do. Thanks sooo much (third time lucky eh? :)).

---

<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:** [June 2, 2003, 10:06am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/19 "2003-06-02T10:06:22Z")

</div>

yup… i always put all my scripts within the first frames. that way i don’t have to go through all my symbols looking for a script. 😛

and you’re welcome. 😉

---

<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:** [June 2, 2003, 10:40am UTC](https://forum.kirupa.com/t/pause-and-mute-for-music/22197/20 "2003-06-02T10:40:40Z")

</div>

by looking at your example it is much easy to understand how the code works  
thank you guys 🙂

[Next page](https://forum.kirupa.com/t/pause-and-mute-for-music/22197.md?page=2)
