2012-01-24 148 views
0

我想停止CS4中的特定聲音,而不必同時停止所有聲音。能夠複製和粘貼簡單的東西真是太棒了,因爲我已經仔細研究了這個問題的答案,並且得到了許多沒有結束工作的巨型巨無霸。 謝謝!Actionscript:在Adobe Flash CS4中停止聲音

+0

本網站不應該被用作獲取複製粘貼代碼塊的資源。 – Marty

回答

2

你正在使用什麼版本的動作,AS2或AS3?

你怎麼彈你的聲音?它是否坐在時間軸上的關鍵幀上?你是否使用actionscript導入它並從庫中播放它?

(編輯時間軸與代碼)

OK,如果時間軸上,你將需要使用ActionScript來播放它,這樣就可以再後來單獨針對它來阻止它。

首先,進入你的圖書館,右鍵點擊你的聲音並編輯它的屬性。你想導出它作爲動作,並給它一個獨特的動作標識符,如'MyGreatSound'。沒有空間等,只有一個字。

將您的聲音從您的關鍵幀中取出。

接下來,在您的操作圖層中創建一個對應於聲音開頭的關鍵幀並將其粘貼; (這裏假定你在庫中給出了'MyGreatSound'的標識符)

var myChannel:SoundChannel = new SoundChannel(); 
var mySound:Sound = new MyGreatSound(); 
myChannel = mySound.play(0); 

這會像以前一樣播放你的聲音。

要停止它,請創建另一個關鍵幀,對應於時間軸上您希望停止聲音的點。

粘貼在下面;

myChannel.stop(); 

您可能會遇到範圍問題,但可以試一試。

更多的例子在這裏:http://www.republicofcode.com/tutorials/flash/as3sound/

+0

我使用的是ActionScript 3.0,聲音確實在時間軸上的關鍵幀中。沒有使用動作來播放它,但聲音文件在庫中。 – user1166091

+0

非常感謝,完美的工作! – user1166091

0

看一看SoundChannel.stop()

有示例代碼提供的,您可以使用和改變:

package { 
    import flash.display.Sprite; 
    import flash.media.Sound; 
    import flash.media.SoundChannel; 
    import flash.net.URLLoader; 
    import flash.net.URLRequest; 
    import flash.text.TextField; 
    import flash.events.MouseEvent; 
    import flash.text.TextFieldAutoSize; 

    public class SoundChannel_stopExample extends Sprite { 
     private var snd:Sound = new Sound(); 
     private var channel:SoundChannel = new SoundChannel(); 
     private var button:TextField = new TextField(); 

     public function SoundChannel_stopExample() { 
      var req:URLRequest = new URLRequest("MySound.mp3"); 
      snd.load(req); 

      button.x = 10; 
      button.y = 10; 
      button.text = "PLAY"; 
      button.border = true; 
      button.background = true; 
      button.selectable = false; 
      button.autoSize = TextFieldAutoSize.CENTER; 

      button.addEventListener(MouseEvent.CLICK, clickHandler); 

      this.addChild(button); 
     } 

     private function clickHandler(e:MouseEvent):void { 
      var pausePosition:int = channel.position; 

      if(button.text == "PLAY") { 
       channel = snd.play(pausePosition); 
       button.text = "PAUSE"; 
      } 
      else { 
       channel.stop(); 
       button.text = "PLAY"; 
      } 
     } 
    } 
} 

來源:Adobe Livedocs - flash.media.SoundChannel

基本上你分配一個SoundSoundChannel,然後停止整個通道(不是聲音本身)。