# Accessing loaded XML information

**URL:** https://forum.kirupa.com/t/accessing-loaded-xml-information/186547
**Category:** flash
**Created:** [April 22, 2006, 5:14am UTC](https://forum.kirupa.com/t/accessing-loaded-xml-information/186547 "2006-04-22T05:14:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![fasterthanlight](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fasterthanlight](https://forum.kirupa.com/u/fasterthanlight)
#### Post date: [April 22, 2006, 5:14am UTC](https://forum.kirupa.com/t/accessing-loaded-xml-information/186547/1 "2006-04-22T05:14:31Z")

</div>

Ok so now i’m adding XML to my little gallery that ive been working on past couple weeks…

here’s my code:

```auto
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml.xml");
function loadXML(loaded) {
    if (loaded) {
        trace("XML LOADED");
        xmlNode = this.firstChild;
        title_a = [];
        type_a = [];
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            title_a* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
            type_a* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
        }
    } else {
        trace("XML ERROR");
    }
}

function displayInfo() {
    trace(title_a[0]);
}
displayInfo();

```

now if you notice the function at the bottom _displayInfo(){_  
thats where I want to display my XML, in this case, the first value in the title\_a array, but it returns undefined and I cant think of the path I would need…

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 22, 2006, 5:36am UTC](https://forum.kirupa.com/t/accessing-loaded-xml-information/186547/2 "2006-04-22T05:36:20Z")

</div>

You are calling _displayInfo_ before the XML has loaded 😉

```auto
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("xml.xml");
function loadXML(loaded) {
 if (loaded) {
  trace("XML LOADED");
  xmlNode = this.firstChild;
  title_a = [];
  type_a = [];
  total = xmlNode.childNodes.length;
  for (i = 0; i < total; i++) {
   title_a* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
   type_a* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
  }
  displayInfo();
 } else {
  trace("XML ERROR");
 }
}
function displayInfo() {
 trace(title_a[0]);
}

```

---

<div class="post-metadata">

### Author: ![fasterthanlight](https://avatars.discourse-cdn.com/v4/letter/f/ecc23a/32.png) [@fasterthanlight](https://forum.kirupa.com/u/fasterthanlight)
#### Post date: [April 22, 2006, 6:00am UTC](https://forum.kirupa.com/t/accessing-loaded-xml-information/186547/3 "2006-04-22T06:00:31Z")

</div>

> [@TheCanadian](#):
>
> You are calling _displayInfo_ before the XML has loaded 😉  
> ActionScript Code:  
> [FONT=Courier New][LEFT]xmlData = [COLOR=#000000] **new** [/COLOR] [COLOR=#0000FF]XML[/COLOR]COLOR=#000000[/COLOR];  
> xmlData.[COLOR=#0000FF]ignoreWhite[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
> xmlData.[COLOR=#0000FF]onLoad[/COLOR] = loadXML;  
> xmlData.[COLOR=#0000FF]load[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000] **function** [/COLOR] loadXMLCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“XML LOADED”[/COLOR][COLOR=#000000])[/COLOR];  
> [COLOR=#0000FF]xmlNode[/COLOR] = [COLOR=#0000FF]this[/COLOR].[COLOR=#0000FF]firstChild[/COLOR];  
> title\_a = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];  
> type\_a = [COLOR=#000000][[/COLOR][COLOR=#000000]][/COLOR];  
> total = [COLOR=#0000FF]xmlNode[/COLOR].[COLOR=#0000FF]childNodes[/COLOR].[COLOR=#0000FF]length[/COLOR];  
> [COLOR=#0000FF]for[/COLOR] [COLOR=#000000]([/COLOR]i = [COLOR=#000080]0[/COLOR]; i \< total; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
> title\_a[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = [COLOR=#0000FF]xmlNode[/COLOR].[COLOR=#0000FF]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000FF]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]0[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]firstChild[/COLOR].[COLOR=#0000FF]nodeValue[/COLOR];  
> type\_a[COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR] = [COLOR=#0000FF]xmlNode[/COLOR].[COLOR=#0000FF]childNodes[/COLOR][COLOR=#000000][[/COLOR]i[COLOR=#000000]][/COLOR].[COLOR=#0000FF]childNodes[/COLOR][COLOR=#000000][[/COLOR][COLOR=#000080]1[/COLOR][COLOR=#000000]][/COLOR].[COLOR=#0000FF]firstChild[/COLOR].[COLOR=#0000FF]nodeValue[/COLOR];  
> [COLOR=#000000]}[/COLOR]  
> displayInfoCOLOR=#000000[/COLOR];  
> [COLOR=#000000]}[/COLOR] [COLOR=#0000FF]else[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000FF]trace[/COLOR][COLOR=#000000]([/COLOR][COLOR=#FF0000]“XML ERROR”[/COLOR][COLOR=#000000])[/COLOR];  
> [COLOR=#000000]}[/COLOR]  
> [COLOR=#000000]}[/COLOR]  
> [COLOR=#000000] **function** [/COLOR] displayInfoCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
> [COLOR=#0000FF]trace[/COLOR]COLOR=#000000[/COLOR];  
> [COLOR=#000000]}[/COLOR]  
> [/LEFT]  
> [/FONT]

Yea fortunately I figured it out soon after i posted here, thanks though :thumb::thumb:
