# onRelease Sound

**URL:** <https://forum.kirupa.com/t/onrelease-sound/106635>\
**Category:** Uncategorized\
**Created:** [April 7, 2004, 2:44pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635 "2004-04-07T14:44:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wyclef](https://avatars.discourse-cdn.com/v4/letter/w/65b543/32.png) [@wyclef](https://forum.kirupa.com/u/wyclef)\
**Post date:** [April 7, 2004, 2:44pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/1 "2004-04-07T14:44:35Z")

</div>

Hello,

Is there a way to attach a sound to onRelease globally?

---

<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 7, 2004, 2:53pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/2 "2004-04-07T14:53:12Z")

</div>

Sure, use this:

```auto

MovieClip.prototype.onRelease = function(){
this.snd = new Sound(this);
this.snd.attachSound("yourSound");
this.snd.start(0,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 7, 2004, 7:41pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/3 "2004-04-07T19:41:23Z")

</div>

so will that work globally for every single button throught a movie???

---

<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 7, 2004, 7:54pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/4 "2004-04-07T19:54:23Z")

</div>

It will work for every button you have call the function . . . 🙂

---

<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 7, 2004, 8:09pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/5 "2004-04-07T20:09:59Z")

</div>

can u upload a basic fla implementing this? i tried it and it is not working…

---

<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 7, 2004, 8:12pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/6 "2004-04-07T20:12:38Z")

</div>

The above code sets the onRelease handler of every movieclip in the movie to play the sound. If you are using Buttons, use this code:

```auto

Button.prototype.onRelease = function(){
var snd = new Sound(this);
snd.attachSound("yourSound");
snd.start(0,1);
}

```

An example fla … well just place some movieclips/buttons on stage give them instance names, place the given code on the timeline and CTRL+ENTER.

---

<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 7, 2004, 9:07pm UTC](https://forum.kirupa.com/t/onrelease-sound/106635/7 "2004-04-07T21:07:27Z")

</div>

This is the script i’m trying to attach button sound to.

[AS]  
// --------------------------------------------------------------------------------------  
function drawButtons() {  
var buttonNames = ["", “01”, “02”, “03”, “04”, “05”];  
var i;  
var l = buttonNames.length;  
for (var c = 1; c\<l; c++) {  
i = this.attachMovie(“button”, “myBtn0”+c, c, {\_y:74+c\*18, \_x:30});  
i.nr = c;  
i.field.text = buttonNames[c];  
i.onRelease = function() {  
this.\_parent.buttonRelease(this, this.nr);  
};  
}  
}  
// --------------------------------------------------------------------------------------  
function buttonRelease(target\_mc, nr) {

```
delete sectionMC_03.folioClip.section_mc.onEnterFrame;

if (nr == 1) {
	myBtn01_func();
} else if (nr == 2) {
	myBtn02_func();
} else if (nr == 3) {
	sectionMC_03.clearPortfolioList();
	myBtn03_func();
} else if (nr == 4) {
	myBtn04_func();
} else if (nr == 5) {
	myBtn05_func();
}

```

}  
// --------------------------------------------------------------------------------------  
this.drawButtons();  
[/AS]
