2011-02-12 43 views
0

嗨所有人都有任何想法,爲什麼這段代碼不起作用?試着抓住聲音元素到Flash CS5-as3

與其他負載[示例圖片]工作完美聲音......不:(

mySoundURL = new URLRequest(var+".mp3"); 
mySoundURLDefault = new URLRequest("default.mp3"); 

try{ 
    sound.load(mySoundURL); 
}catch(e:IOErrorEvent){ 
    trace("Can't load sound: "+e); 
    sound.load(mySoundURLDefault); 
} 

這是我得到的錯誤:

Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error 

感謝和美好的一天

回答

0

這篇帖子中沒有太多資料,我建議檢查以下條件:

1)Is您的var+".mp3"正確的URI?它是否指向現有文件?只需在瀏覽器中嘗試 - 它是否應該找到該文件? 如果你是一個指向文件在互聯網你應該使用符號像http://site.com/song.mp3 如果你試圖播放硬盤上的文件,你應該使用像C直接文件地址:/audio/song.mp3

2)如果它的URI與可能的文件不一致,則不是MP3格式。

3)你可以嘗試的SoundLoaderContext玩像

  var mySoundURL = new URLRequest(var+".mp3") 
      var context:SoundLoaderContext = new SoundLoaderContext(0, false); 
      snd.load(mySoundURL , context); 
3

你做裝載機使用try/catch語句。這裏是你做什麼,而不是:

sound.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorEvent); 
sound.load(mySoundURL); 

private function onIOErrorEvent(e:IOErrorEvent):void{ 
    trace(e); 
    trace(e.message); 

    //^This will show you the file it tried to load and failed at 

    e.currentTarget.removeEventListener(IOErrorEvent.IOError, onIOErrorEvent); 
    e.currentTarget.removeEventListener(Event.COMPLETE, onComplete; 
    //^don't forget to clean up your listeners! 
} 

這樣做的原因是,正如你所看到的,未被捕獲的錯誤不會告訴你任何有幫助的,比如它的聲音加載失敗,或者你想的網址聯繫了。

我認爲@Alexander Sobolev在他的第一次猜測上走在了正確的軌道上,基於你仍然有錯誤的事實。處理加載器中的錯誤與處理來自同步代碼的錯誤不同,try/catch在這裏不會幫助你。

如果您想嘗試從第一個失敗播放alt聲音,您可以在onIOErrorEvent函數中執行此操作。

你聽IOErrorEvent其他時候用裝載機當加載SWF或圖像文件

loader.contentLoaderInfo.addEventListener(IOErrorEvent.... 

或者使用URLLoader

urlLoader.addEventListener(IOErrorEvent...