加载MP3播放器时出现xml错误

时间:2012-01-19 23:01:17

标签: xml flash actionscript-3 actionscript

我在加载MP3播放器时遇到错误,这是我按Ctrl + Enter时得到的内容。

TypeError: Error #1090: XML parser failure: element is malformed.
  at moviesound_fla::MainTimeline/getsongs()
  at flash.events::EventDispatcher/dispatchEventFunction()
  at flash.events::EventDispatcher/dispatchEvent()
  at flash.net::URLLoader/onComplete()

这是我使用的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>

这是我的动作脚本

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].@atitle;
    var song:Sound=new Sound(new URLRequest(songlist.song[currentsong].@url));
    sc=song.play();
    sc.addEventListener(Event.SOUND_COMPLETE,songend);
}
function songend(e:Event):void {
    e.target.stop();
    currentsong++;
    playsong();
}

只有两个按钮是前一个(b_btn)和下一个(n_btn)

此动作脚本是否有任何错误,或者只有在将其放在网页上后才能生效?

1 个答案:

答案 0 :(得分: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>