Flash 声音通道,移除Venthandler,AS3
有没有更好的方法来使用AS3声道?这是可行的,但我讨厌当我点击播放按钮两次,它开始加倍。请告知Flash 声音通道,移除Venthandler,AS3,flash,actionscript-3,Flash,Actionscript 3,有没有更好的方法来使用AS3声道?这是可行的,但我讨厌当我点击播放按钮两次,它开始加倍。请告知 var mySound:Sound = new Sound(); playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler); var myChannel:SoundChannel = new SoundChannel(); function myPlayButtonHandler (e:MouseEvent)
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_;
}
只需使用
removeEventListener()
在声音持续时间内分离myPlayButtonHandler
var mySound:Sound = new Sound();
playButton.addEventListener (MouseEvent.CLICK, myPlayButtonHandler);
var myChannel:SoundChannel = new SoundChannel();
function myPlayButtonHandler (e:MouseEvent):void {
myChannel = mySound.play();
removeEventListener(MouseEvent.CLICK, myPlayButtonHandler);
}
stopButton.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
myChannel.stop();
removeEventListener(MouseEvent.CLICK, myPlayButtonHandler);
}
/*-----------------------------------------------------------------*/
//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_;
}