Xml & flash 8

Hi all,

I’ve got a little question regarding XML in Flash 8.

My XML file:


<?xml version="1.0"  encoding="utf-8"?>

<objecten>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 1</content>
    </entry>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 2</content>
    </entry>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 3</content>
    </entry>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 4</content>
    </entry>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 5</content>
    </entry>
    <entry>
        <image>img/kaart.jpg</image>
        <content>tekst 6</content>
    </entry>
</objecten>

Is it possible that, when I click on a button, a specific childNode is loaded in my .swf?
I think I’m almost there, 'cause I’ve put this on my first button:


on(release) {
    function loadXML(loaded) {
    if (loaded) {
        _root.img = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
        _root.content = this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
        imgHolder.loadMovie(_root.img);
        txtStart.text = _root.content;
    } 
    else {
        trace("file not loaded!");
    }
}

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("content.xml");
}

… and that works like a charm, but when I put the script on my second button & I make some changes like say


_root.img = this.firstChild.childNodes[0].childNodes[**2**].firstChild.nodeValue;
_root.content = this.firstChild.childNodes[0].childNodes[**3**].firstChild.nodeValue;

, I get an ‘undefined’ on the screen.

In a nutshell what I want is this:

  • when clicked on button 1, tekst1 & img1 appear
  • when clicked on button 2, tekst2 & img2 appear

Edit after 5 minutes or so:
Okay, I’ve found the answer: instead of making the changes I tried above, you just have to change the first [0] into [1], [2], etc.
You have to change it for all nodes; _root.img & _root.content in this case.
The only thing I’m not entirely sure off is the usage of _root. …