# Returning values for XML nodes

**URL:** <https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739>\
**Category:** Uncategorized\
**Created:** [May 30, 2008, 11:55am UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739 "2008-05-30T11:55:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrissyb](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@chrissyb](https://forum.kirupa.com/u/chrissyb)\
**Post date:** [May 30, 2008, 11:55am UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739/1 "2008-05-30T11:55:54Z")

</div>

Hello people…

I’m trying to return values from my XML in order to attach a movie. Basically when a slide chages it calls a movie from the library.

I have got this far - which looks bloated to me:

```auto
function parse():Void {
if (xmlData.firstChild.nodeName == "girls") {
var rootNode:XMLNode = xmlData.firstChild;
for (i=0; i<rootNode.childNodes.length; i++) 
{
if (rootNode.childNodes*.nodeName == "slide") {
    
 trace ("slide_1")
 
 }
 
 if (rootNode.childNodes*.nodeName == "slide2") {
    
 trace ("slide_2")

 }
 
  if (rootNode.childNodes*.nodeName == "slide3") {
    
 trace ("slide_3")

 }
 
  if (rootNode.childNodes*.nodeName == "slide4") {
    
 trace ("slide_4")}
 
  if (rootNode.childNodes*.nodeName == "slide5") {
    
 trace ("slide_5")}
 
  if (rootNode.childNodes*.nodeName == "slide6") {
    
 trace ("slide_6")}
}}}

```

The fuction ‘parse’ is called initially when I’m loading the XML.

No in the output panel I get slide1,slide2,slide3 etc. This made me very happy! Except obviously if I try and extend the function and call the movieclips using attachMovie, it’s going to try and call them all at once :stare:.

How to a differentiate between slides now. What is my next step?

Any help, pointers or if I’m in the wrong area completely - let me know!

Thanks as always!

Chris

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 30, 2008, 6:05pm UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739/2 "2008-05-30T18:05:35Z")

</div>

dont use a for loop here. use for loop only to parse the xml and store the data in a array.

function parse():Void {  
if (xmlData.firstChild.nodeName == “girls”) {  
var rootNode:XMLNode = xmlData.firstChild;

for (i=0; i\<rootNode.childNodes.length; i++)  
{  
array.push(rootNode.childNodes\*.nodeName);  
}

later keep a counter variable set to 0;

and then over a time interval load data from the array using myarray[counter] and use it for attaching movieclip if you want.

---

<div class="post-metadata">

**Author:** ![chrissyb](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@chrissyb](https://forum.kirupa.com/u/chrissyb)\
**Post date:** [May 30, 2008, 7:01pm UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739/3 "2008-05-30T19:01:06Z")

</div>

Thank you sparkdemon for your input. But I haven’t got a clue how to proceed :crying:. Setting up the array sounds like a grand idea - but aren’t I effectively setting up two arrays?

I already have on array - which is the XML. So we’re effectively pushing one array onto another?

Forgive me - could you elaborate a little further for me…

Chris

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 30, 2008, 7:30pm UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739/4 "2008-05-30T19:30:26Z")

</div>

my pleasure… just say what you need… to go with 🙂

[quote=chrissyb;2333769]Thank you sparkdemon for your input. But I haven’t got a clue how to proceed :crying:. Setting up the array sounds like a grand idea - but aren’t I effectively setting up two arrays?

I already have on array - which is the XML. So we’re effectively pushing one array onto another?

Forgive me - could you elaborate a little further for me…

Chris[/quote]

---

<div class="post-metadata">

**Author:** ![chrissyb](https://avatars.discourse-cdn.com/v4/letter/c/ce73a5/32.png) [@chrissyb](https://forum.kirupa.com/u/chrissyb)\
**Post date:** [May 31, 2008, 7:42am UTC](https://forum.kirupa.com/t/returning-values-for-xml-nodes/261739/5 "2008-05-31T07:42:11Z")

</div>

Hello

Basically I want to attach a different movie from the library - when my xml slide changes. It is so I can have animated titles for the pictures.

So in my first post I could trace each node of the xml, but it’s how to turn this value into an action to call a movie clip.

> later keep a counter variable set to 0;

and then over a time interval load data from the array using myarray[counter] and use it for attaching movieclip if you want.  
I honestly don’t know how to achieve this. Here is a shot…

```auto
function parse():Void {
if (xmlData.firstChild.nodeName == "girls") {
var rootNode:XMLNode = xmlData.firstChild;
}
for (i=0; i<rootNode.childNodes.length; i++)

myArray.push(rootNode.childNodes*.nodeName);
}

trace(myArray.length);

if (myArray [x])

{_this.attachMovie("mcgirl1", "girl_mc", this.getNextHighestDepth(), {_x:Stage.width / 2, _y:Stage.height / 2});

}

```

This doesn’t work, but i gave it a go. I don’t understand if we already have the XML as effectively an array we need to create another one.

That is I THINK why I’m asking for help!!! Thanks sparkdemon…

Chris
