# Ultra basic XML help please

**URL:** <https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796>\
**Category:** flash\
**Created:** [May 8, 2008, 7:21pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796 "2008-05-08T19:21:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [May 8, 2008, 7:21pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/1 "2008-05-08T19:21:57Z")

</div>

I’ve never used XML before, at all.

However I have an upcoming project that’s going to have a big image gallery, that is likely to change often, so I can see XML would be very useful for speed of editing/adding etc.

I’m a complete XML noob then, and I’m just doing a little test with some text, and I can’t seem to access the Array outside the xml.onLoad function.

Could you tell me what I am doing wrong?

Here is the xml…

```auto
<?xml version="1.0" encoding="iso-8859-1"?>
<writing>
<para>
OK this is paragraph 1
</para>
<para>
And this is paragraph 2
</para>
<para>
Bloody hell, XML seems like a bit of a nause
</para>
</writing>

```

And here is the AS…

```auto
stop();
var xml:XML = new XML();
xml.ignoreWhite = true;
var description:Array = new Array();
xml.load("writing.xml");
xml.onLoad = function(loaded) {
 if (loaded) {
  paragraphs = this.firstChild.childNodes;
  for (var i = 0; i<paragraphs.length; i++) {
   description.push(paragraphs*.firstChild);
  }
 }
[COLOR=black]**desc.text = description[2];**[/COLOR]
};

```

Now in the above code, my dynamic text field named “desc” correctly displays “bloody hell, XML is a nause”.

However, when the line in bold is placed outside the onLoad function, it returns undefined, and when traced, the description array returns nothing at all.

I need to access the array outside of this function.

What am I doing wrong?

Cheers,  
Joe

---

<div class="post-metadata">

**Author:** ![Valaran](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@Valaran](https://forum.kirupa.com/u/Valaran)\
**Post date:** [May 9, 2008, 5:05am UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/2 "2008-05-09T05:05:24Z")

</div>

Let me tell you why its undefined, the array is empty until the XML file has been loaded. And if you place the “desc.text = description[2];” outside of the function, it gets called before the file has been loaded 🙂

To get around this, you can either call a function from within the xml.onLoad() or put the “desc.text = description[2];” on the next frame.

---

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [May 9, 2008, 8:40am UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/3 "2008-05-09T08:40:05Z")

</div>

Is that it? 😃

Thanks, I’ll give that a go. That crossed my mind, until I decided it wasn’t that, because I’m testing it locally obviously, so the XML file should be loaded immediately, AND I put the “desc.text = description[2];” after the code populating the array.

---

<div class="post-metadata">

**Author:** ![Valaran](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@Valaran](https://forum.kirupa.com/u/Valaran)\
**Post date:** [May 9, 2008, 5:07pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/4 "2008-05-09T17:07:02Z")

</div>

Well, I made a simple test, and thats the case 🙂 I tried putting it after the load call aswell, but the interval between actionscript calls and actually loading data from a file is too big.

Anyway, good luck now!

---

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [May 9, 2008, 5:31pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/5 "2008-05-09T17:31:27Z")

</div>

Superb, that was indeed it, I put it on the next frame and it worked absolutely fine, I also called from another function elsewhere, and it worked fine too. Thanks.

Incidentally, one more problem - apostrophes are not being displayed correctly.

“It’s” is being displayed as “it’s” 😃

Any ideas?

Cheers,  
Joe

---

<div class="post-metadata">

**Author:** ![rumblesushi](https://avatars.discourse-cdn.com/v4/letter/r/b38774/32.png) [@rumblesushi](https://forum.kirupa.com/u/rumblesushi)\
**Post date:** [May 9, 2008, 6:01pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/6 "2008-05-09T18:01:33Z")

</div>

Nevermind, figured it out, I just had to stick on nodeValue after firstChild to register it as text.

I have to say, while XML is undoubtedly useful, and pretty easy too - somehow I find it annoying to work with.

---

<div class="post-metadata">

**Author:** ![Valaran](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@Valaran](https://forum.kirupa.com/u/Valaran)\
**Post date:** [May 9, 2008, 6:18pm UTC](https://forum.kirupa.com/t/ultra-basic-xml-help-please/259796/7 "2008-05-09T18:18:27Z")

</div>

Me too, I hate working with XML in flash, although as you say, its useful.
