2011-10-19 52 views
0

我試圖製作一個簡單的交互式Flash動畫,因此當您滾動一個看不見的按鈕時,音色庫會播放聲音,那麼當您播放聲音時會停止。ActionScript3在ROLL_OUT上停止聲音

到目前爲止,我有這個

import flash.events.Event; 
import flash.media.SoundChannel; 

stop(); 

button1.addEventListener(MouseEvent.ROLL_OVER,playSound); 
function playSound(event:Event) { 
var mySound:elmosample = new elmosample(); 
var myCahnnel:SoundChannel = mySound.play(); 
}` 

有沒有辦法一個新的開始時停止聲音ROLL_OUT播放或停止當前的聲音?

回答

0

也許寫出一個功能推出? 類似於

button1.addEventListener(MouseEvent.ROLL_OUT,stopSound);

並且只能一次播放一首歌曲 可能會將您的聲音變量名稱放入一個數組 並且只使用一個頻道? 但我不知道你怎麼玩一個新的聲音 所以我不能給你一個明確的答案

希望這有助於

+0

我寫了一個新的功能 button2.addEventListener(MouseEvent.ROLL_OUT ,stopSound); function stopSound(event:Event){ \t var mySound:elmosample1 = new elmosample1(); \t var myCahnnel:SoundChannel = mySound.stop(); \t } 但現在得到輸出錯誤 TypeError:錯誤#1006:停止不是函數。 \t at _fla :: MainTimeline/stopSound() –

+0

您無法使用聲音類在AS3中使用其聲道停止聲音,因此請嘗試MyChannel.stop(); 這似乎是一個很好的嘖嘖聲:http://www.republicofcode.com/tutorials/flash/as3sound/ –

0
import flash.events.Event; 
import flash.media.SoundChannel; 

stop(); 

var mySound:Sound; 
var myChannel:SoundChannel; 

button1.addEventListener(MouseEvent.ROLL_OVER, onRollOver); 
button1.addEventListener(MouseEvent.ROLL_OUT, onRollOut); 

function onRollOver(e:Event):void 
{ 
    //stop previous sounds 
    if(myChannel) 
    myChannel.stop(); 

    mySound = new elmosample(); 
    myChannel = mySound.play(); 
} 

function onRollOut(e:Event):void 
{ 
    myChannel.stop(); 
}