2010-12-15 116 views
0

在我的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; 
} 

回答

1

你確定你沒有意外地在時間軸上添加聲音嗎?如果不是,則應在方法chooseSong中添加一個跟蹤,並檢查在加載項目時是否觸發它。

我在舞臺和這個腳本上創建了一個帶有mc(song1)的新文件。這對你有用嗎?

song1.addEventListener(MouseEvent.CLICK, chooseSong); 

function chooseSong(e:MouseEvent):void { 
    trace (e.currentTarget.name) 
} 
+0

那麼你知道什麼,我確實把它加到了他的時間線上。刪除了,但現在沒有什麼玩,當你點擊按鈕。 – Expecto 2010-12-15 21:31:30

+0

你在函數中得到正確的聲音url嗎?跟蹤(currSong)後切換。 – Mattias 2010-12-15 21:35:56

+0

我沒有得到任何東西 - 並且添加跟蹤(currSong)也不會做任何事情,當您按下按鈕時間段時沒有任何反應。 – Expecto 2010-12-15 21:43:16

1

這僅僅是一個在黑暗中拍攝,但你並沒有發生歌曲意外添加到某個階段?這可能會導致歌曲在電影加載時自動播放。

檢查您的控件以及一個簡單的錯誤點擊可能是問題。