2010-04-05 1 views
0

Existe-t-il une meilleure façon d'utiliser le canal audio AS3? Cela fonctionne, mais je déteste quand j'appuie sur le bouton de lecture deux fois et il commence à doubler. S'il vous plaît donnez votre avis.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_;  
      } 

Répondre

1

Il suffit d'utiliser removeEventListener() pour détacher myPlayButtonHandler pendant toute la durée du son.

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