在我的Flash項目中的一個框架中有6個按鈕。當你點擊一個按鈕時,不同的歌曲播放。簡單。問題是,列表中的第一首歌正在播放第二個項目,而不是等待某個人點擊按鈕!聲音自動播放 - 閃光燈
import fl.events.SliderEvent;
var snd:Sound;
var channel:SoundChannel;
var trans:SoundTransform;
var currSong:String;
var currVol:Number = .5;
var currPan:Number = 0;
var songList:Array=new Array("Drifting.mp3","Push.mp3",
"Stupid.mp3","Train Wreck.mp3","World on Fire.mp3","Fallen.mp3");
panSlide.visible=false;
volSlide.visible=false;
song1.addEventListener(MouseEvent.CLICK, chooseSong);
song2.addEventListener(MouseEvent.CLICK, chooseSong);
song3.addEventListener(MouseEvent.CLICK, chooseSong);
song4.addEventListener(MouseEvent.CLICK, chooseSong);
song5.addEventListener(MouseEvent.CLICK, chooseSong);
song6.addEventListener(MouseEvent.CLICK, chooseSong);
panSlide.addEventListener(SliderEvent.CHANGE, panChange);
volSlide.addEventListener(SliderEvent.CHANGE, volumeChange);
function chooseSong(e:MouseEvent):void {
switch (e.currentTarget.name) {
case "song1":
currSong = "../MP3s/"+songList[0] as String;
break;
case "song2":
currSong = "../MP3s/"+songList[1] as String;
break;
case "song3":
currSong = "../MP3s/"+songList[2] as String;
break;
case "song4":
currSong = "../MP3s/"+songList[3] as String;
break;
case "song5":
currSong = "../MP3s/"+songList[4] as String;
break;
case "song6":
currSong = "../MP3s/"+songList[5] as String;
break;
}
if (snd != null) {
channel.stop();
}
snd = new Sound();
snd.load(new URLRequest(currSong));
channel = new SoundChannel ;
trans = new SoundTransform(currVol,currPan);
channel = snd.play();
channel.soundTransform = trans;
panSlide.visible = true;
volSlide.visible = true;
}
function volumeChange(e:SliderEvent):void {
currVol = e.target.value;
trans.volume = currVol;
channel.soundTransform = trans;
}
function panChange(e:SliderEvent):void {
currPan = e.target.value;
trans.pan = e.target.value;
channel.soundTransform = trans;
}
那麼你知道什麼,我確實把它加到了他的時間線上。刪除了,但現在沒有什麼玩,當你點擊按鈕。 – Expecto 2010-12-15 21:31:30
你在函數中得到正確的聲音url嗎?跟蹤(currSong)後切換。 – Mattias 2010-12-15 21:35:56
我沒有得到任何東西 - 並且添加跟蹤(currSong)也不會做任何事情,當您按下按鈕時間段時沒有任何反應。 – Expecto 2010-12-15 21:43:16