2011-09-14 48 views
3

我有這個代碼在第二幀播放歌曲,它工作正常。我的音樂庫中的聲音類別是「MySound」。如何阻止在as3中播放聲音?

var snd:MySound = new MySound 
snd.play(); 

現在我需要歌曲停止播放後一幀。

+0

snd.stop()????? –

+0

@The_asMan [聲音](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Sound.html)不執行'stop()'。 –

回答

11

你必須使用這個SoundChannel類:

var mySound:Sound = new Sound(); 
var myChannel:SoundChannel = new SoundChannel(); 
mySound.load(new URLRequest("myFavSong.mp3")); 
myChannel = mySound.play(); 

// ... 

myChannel.stop(); 

參考:http://www.republicofcode.com/tutorials/flash/as3sound/(第4章 - 停止一個聲音

1
//*This code for playing the sound after import to the library* 
var mySound:Sound = new MenuMusic(); 
var myChannel:SoundChannel = new SoundChannel(); 
myChannel = mySound.play(); 

//*This code for the nextframe button* 
btn_easy.addEventListener(MouseEvent.MOUSE_DOWN, btneasy); 
function btneasy(event:MouseEvent):void 
{ 
    gotoAndPlay(62); 
    myChannel.stop(); 
} 

提醒

你不必拖g將聲音文件添加到時間線中。只需將 代碼粘貼到按鈕的指定操作腳本。

var mySound:Sound = new MenuMusic(); 

'MenuMusic' 可以改變你想要什麼。只需右鍵單擊庫中的聲音 文件,然後選擇「屬性」。點擊動作腳本選項卡和 檢查「爲ActionScript導出」和你現在可以在 「類」輸入框更名..

它的工作這麼沒什麼問題:)

希望它解決了這個問題! :D