onRelease Sound

Hello,

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

Sure, use this:


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

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

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

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

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:


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.

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]