2010-04-05 28 views
0

有没有更好的方法来使用声道是AS3?这有效,但我讨厌它,当我点击播放按钮两次,它开始加倍。请指教。SoundChannel,removeEventHandler,AS3

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_;  
      } 

回答

1

只需使用removeEventListener()脱离myPlayButtonHandler对声音的持续时间。

1
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_;  
      }