停止AS3中的声音

问题描述:

我正在为相册制作一些互动广告。它有4个可拖动的歌曲标题,当放在目标上时,开始播放歌曲。试图找出如何停止播放新歌时播放的歌曲。这里是我的代码:停止AS3中的声音

package { 
     import flash.display.*; 
     import flash.events.*; 
     import flash.media.Sound; 
     import flash.media.SoundChannel; 
     import flash.net.URLRequest; 

    public class Deftones extends MovieClip{ 

     function Deftones() { 

      swerve1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS); 
      swerve1.addEventListener(MouseEvent.MOUSE_UP, dragEndS); 
      polt1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS); 
      polt1.addEventListener(MouseEvent.MOUSE_UP, dragEndS); 
      rd1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS); 
      rd1.addEventListener(MouseEvent.MOUSE_UP, dragEndS); 
      gauze1.addEventListener(MouseEvent.MOUSE_DOWN, dragStartS); 
      gauze1.addEventListener(MouseEvent.MOUSE_UP, dragEndS); 
      var sound1:Sound= new Sound(); 
      var sound2:Sound= new Sound(); 
      var sound3:Sound= new Sound(); 
      var sound4:Sound= new Sound(); 
      sound1.load(new URLRequest("music/Swerve_City.mp3")); 
      sound2.load(new URLRequest("music/Poltergeist.mp3")); 
      sound3.load(new URLRequest("music/Romantic_Dreams.mp3")); 
      sound4.load(new URLRequest("music/Gauze.mp3")); 
      var channel:SoundChannel= new SoundChannel(); 

      function dragStartS(e:MouseEvent){ 
       e.currentTarget.startDrag(); 
      } 
      function dragEndS(e:MouseEvent){ 
       e.currentTarget.stopDrag(); 
       if (swerve1.hitTestObject(speaker1)){ 
        channel.stop(); 
        sound1.play(0); 
       } 
       else if (polt1.hitTestObject(speaker1)){ 
        channel.stop(); 
        sound2.play(0); 
       } 
       else if (rd1.hitTestObject(speaker1)){ 
        channel.stop(); 
        sound3.play(0); 
       } 
       else if (gauze1.hitTestObject(speaker1)){ 
        channel.stop(); 
        sound4.play(0); 
       } 
      } 

     } 
    } 

任何帮助,我将不胜感激。

您可以使用SoundMixer.stopAll()

停止所有的声音正在播放。

+0

谢谢!这工作完美。 –

可以使用SoundChannel类对于这一点,看看in this link(第4节 - 停止一个声音)

+0

谢谢!我去了SoundMixer.stopALL()...为我需要它的作品。 –