2012-01-19 113 views
0

加載MP3播放器時出現錯誤,這是我按Ctrl + Enter時出現的問題。xml加載MP3播放器時出錯

TypeError:錯誤#1090:XML解析器失敗:元素格式錯誤。 在moviesound_fla :: MainTimeline/getsongs() 在flash.events::EventDispatcher/dispatchEventFunction() 在flash.events::EventDispatcher/dispatchEvent() 在flash.net::URLLoader/onComplete()

這是我用

<?xml version="1.0" encoding="UTF-8"?> 
<songs> 

<song atitle="Blind Willie" aurl="blind_willie.mp3" /> 

<song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" /> 

<song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" /> 

<song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" /> 

</songs> 

</xml> 

這裏的XML是我的動作腳本

var getfile:URLLoader=new URLLoader(new URLRequest('song.xml')); 

var amountofsongs:int=0; 
var currentsong:int=0; 
var songlist:XML = new XML(); 
var sc:SoundChannel=new SoundChannel(); 

getfile.addEventListener(Event.COMPLETE, getsongs); 
n_btn.addEventListener(MouseEvent.MOUSE_DOWN,n_song); 
b_btn.addEventListener(MouseEvent.MOUSE_DOWN,b_song); 

function getsongs(e:Event):void { 
    songlist = XML(e.target.data); 
    amountofsongs = songlist.song.length()-1; 
    playsong(); 
} 

function n_song(e:MouseEvent):void { 
    currentsong++; 
    playsong(); 
} 
function b_song(e:MouseEvent):void { 
    currentsong--; 
    playsong(); 
} 

function playsong():void{ 
    sc.stop(); 
    if (currentsong>amountofsongs){ 
     currentsong=0; 
    }if (currentsong<0){ 
     currentsong=amountofsongs; 
    } 
    song_txt.text=songlist.song[currentsong][email protected]; 
    var song:Sound=new Sound(new URLRequest(songlist.song[currentsong][email protected])); 
    sc=song.play(); 
    sc.addEventListener(Event.SOUND_COMPLETE,songend); 
} 
function songend(e:Event):void { 
    e.target.stop(); 
    currentsong++; 
    playsong(); 
} 

只有兩個按鈕,這是以前的(b_btn)和未來(n_btn)

此操作腳本中是否有任何錯誤,或者只有將它放在網頁上後纔有效?

+1

之前第一乘坐空間了呢?並刪除 –

回答

2

一個正確的XML的文件是:

<?xml version="1.0" encoding="UTF-8"?> 
<songs> 
    <song atitle="Blind Willie" aurl="blind_willie.mp3" /> 
    <song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" /> 
    <song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" /> 
    <song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" /> 
</songs> 

沒有必要使用</xml>

+0

是的工作,但然後顯示這樣的東西.. 錯誤#2044:未處理的IOErrorEvent :.文本=錯誤#2032:流錯誤。 \t在moviesound_fla :: MainTimeline/playsong() \t在moviesound_fla :: MainTimeline/getsongs() \t在flash.events::EventDispatcher/dispatchEventFunction() \t在flash.events::EventDispatcher/dispatchEvent() \t在flash.net::URLLoader/onComplete() –

+1

'songlist.song [currentsong]。@ url' 您命名一個屬性'aurl',但嘗試獲取一個名爲'url'的屬性。試試這個: 'songlist.song [mixtong]。@ aurl' –

+0

嘿,它的工作:)謝謝埃敏,你發現我犯的錯誤。 –