SoundChannel, removeEventHandler, AS3
Posted
by pixelGreaser
on Stack Overflow
See other posts from Stack Overflow
or by pixelGreaser
Published on 2010-04-05T21:38:59Z
Indexed on
2010/04/06
1:13 UTC
Read the original article
Hit count: 302
flash
|actionscript-3
Is there a better way to use the sound channel is AS3? This works, but I hate it when I tap the play button twice and it starts doubling. Please advise.
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
function myPlayButtonHandler (e:MouseEvent):void {
myChannel = mySound.play();
}
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
}
/*-----------------------------------------------------------------*/
//global sound buttons, add instance of 'killswitch' and 'onswitch' to stage
killswitch.addEventListener(MouseEvent.CLICK, clipKillSwitch);
function clipKillSwitch(e:MouseEvent):void{
var transform1:SoundTransform=new SoundTransform();
transform1.volume=0;
flash.media.SoundMixer.soundTransform=transform1;
}
onswitch.addEventListener(MouseEvent.CLICK, clipOnSwitch);
function clipOnSwitch(e:MouseEvent):void{
var transform1_:SoundTransform=new SoundTransform();
transform1_.volume=1;
flash.media.SoundMixer.soundTransform=transform1_;
}
© Stack Overflow or respective owner