PDA

View Full Version : AS3 - Sound button


spark067
09-10-2008, 05:37 PM
Hello everyone,

I have a question that I have three sound buttons click to hear a sound. It works only one button with below the code. How to make to work with three sound buttons? Looks like simple but I can't figure it out. Am I using a wrong code here? Please help me.

var loadSnd:URLRequest = new URLRequest("SORTER.mp3");
var thisSnd:Sound = new Sound();
var sndTrans:SoundChannel = new SoundChannel();

thisSnd.load(loadSnd);

play_btn.addEventListener(MouseEvent.CLICK, playF);
stop_btn.visible = false;
stop_btn.addEventListener(MouseEvent.CLICK, stopF);

function playF(event:MouseEvent):void{
SoundMixer.stopAll();
sndTrans = thisSnd.play();
play_btn.visible = false;
stop_btn.visible = true;
}

function stopF(event:MouseEvent):void{
sndTrans.stop();
stop_btn.visible = false;
play_btn.visible = true;
}

Any help would be greatly appreciated.

Thanks,

chemicaluser
09-11-2008, 04:00 AM
not sure if i understand your question. you have 3 buttons and you want them to play the same sound when any one of the buttons is clicked, right?

if so.. the problem would be that in your code you only have one event listener
play_btn.addEventListener(MouseEvent.CLICK, playF);

you have to add the event listeners to the other buttons which are calling the playF function, basically copy the line but change the play_btn to whatever the instance name is of your other buttons is.


play_btn.addEventListener(MouseEvent.CLICK, playF);
button1.addEventListener(MouseEvent.CLICK, playF);
button2.addEventListener(MouseEvent.CLICK, playF);



and if i misunderstood your question, .... i don't know, good luck. lol