Akhil Paul
Akhil Paul

Reputation: 721

xml error while loading mp3 player

I'm having an error while loading an mp3 player, here is what I getting when hitting 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()

This is the xml I used

<?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>

Here is my action script

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();
}

There are only two buttons which is previous (b_btn) and next (n_btn)

Is there any errors on this action script or it may only work after placed it on a webpage?

Upvotes: 0

Views: 358

Answers (1)

Emin A. Alekperov
Emin A. Alekperov

Reputation: 1067

A correct XML-file is:

<?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>

There is no need to use </xml>

Upvotes: 2

Related Questions