# For Loops

**URL:** <https://forum.kirupa.com/t/for-loops/280773>\
**Category:** flash\
**Created:** [January 31, 2009, 5:03pm UTC](https://forum.kirupa.com/t/for-loops/280773 "2009-01-31T17:03:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alemieux34](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@alemieux34](https://forum.kirupa.com/u/alemieux34)\
**Post date:** [January 31, 2009, 5:03pm UTC](https://forum.kirupa.com/t/for-loops/280773/1 "2009-01-31T17:03:05Z")

</div>

I’ve got some code to pull info from an XML file for an MP3 player. The way it’s coded though, it only pulls the first record[0]. I’m trying to write for loops to pull other info into some dynamic text fields and have play buttons for each track in the XML file:

Here’s the code:

```auto
function onLoadXML(ev:Event) {
    try {
        var myXML:XML = new XML(ev.target.data);
        var list:XMLList = myXML.track;
        displayDetails(list[0].@artist, list[0].@album, list[0].@title);
        trace(displayDetails);
        playSong(list[0].@source);
        // populateList(list);
    } catch (e:TypeError) {
        trace("could not parse the XML");
        trace(e.message);
    }
}
function displayDetails(artist:String, album:String, title:String) {
    trackInfo1.text = artist + "	" + album + "	" + title;
}
var song:SoundChannel;
var soundFactory:Sound = new Sound();
function playSong(id:String) {
    var url:String = id;
    var request:URLRequest = new URLRequest(url);
    soundFactory.addEventListener(Event.COMPLETE, completeHandler);
    soundFactory.addEventListener(Event.ID3, id3Handler);
    soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    soundFactory.addEventListener(ProgressEvent.PROGRESS, progressHandler);
    soundFactory.load(request);
    // song = soundFactory.play();
    play_btn.buttonMode = true;
    play_btn.addEventListener(MouseEvent.CLICK, playTrack);
    play_btn.addEventListener(MouseEvent.MOUSE_OVER, playOver);
    play_btn.addEventListener(MouseEvent.MOUSE_OUT, playUp);
}

function playTrack(e:MouseEvent):void {
    SoundMixer.stopAll();
    song = soundFactory.play();
    play_btn.enabled = false;
    play_btn.mouseEnabled = false;
    play_btn.gotoAndStop("off");
    play_btn.alpha = .5;
}

```

I think it’s these two lines that I need for loops for:

displayDetails(list[0].@artist, list[0].@album, list[0].@title);

playSong(list[0].@source);

What I was trying to use is:

for(var:Number = i; i \<list.length; i++)  
displayDetails(list\*.@artist, list\*.@album, list\*.@title);  
}

This kind of works, but when I try to display the tracks into multiple dynamic text fields, it only shows the last track in the XML file.
