# XML and Actionscript Problem - Help!

**URL:** <https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821>\
**Category:** flash\
**Created:** [March 30, 2006, 11:38am UTC](https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821 "2006-03-30T11:38:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmy\_jazz](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jimmy\_jazz](https://forum.kirupa.com/u/jimmy_jazz)\
**Post date:** [March 30, 2006, 11:38am UTC](https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821/1 "2006-03-30T11:38:49Z")

</div>

Hi

Im having trouble getting Flash to return the total number \<ProjectImage\> nodes in the following xml.

```auto

<?xml version="1.0" ?>
<work>
  <project>
    <projectName>Project One</projectName> 
    <projectCat>Category One </projectCat> 
    <projectDesc>Project One Description</projectDesc>
    <images>
      <ProjectImage>project1-image1.jpg</ProjectImage>
      <ProjectImage>project1-image2.jpg</ProjectImage>
    </images>
  </project>
  <project>
    <projectName>Project Two</projectName> 
    <projectCat>Category Two</projectCat> 
    <projectDesc>Project Two Description</projectDesc>
    <images>
      <ProjectImage>project2-image1.jpg</ProjectImage>
      <ProjectImage>project2-image2.jpg</ProjectImage>
      <ProjectImage>project2-image3.jpg</ProjectImage>
    </images>
  </project>
</work>

```

Im trying to get the Total number of images for each project. But it only returns the first image for each project…  
Do I need to nest a loop within the project loop to get the images for that project?

[AS]  
function loadXML(loaded) {  
if (loaded) {  
projectNode = this.firstChild;

```
	projectName = [];
	projectcat = [];
	description = [];
	image = [];
	total = projectNode.childNodes.length;
	
	for (i=0; i&lt;total; i++) {
		
		projectName* = projectNode.childNodes*.childNodes[0].firstChild.nodeValue;
		projectcat* = projectNode.childNodes*.childNodes[1].firstChild.nodeValue;
		description* = projectNode.childNodes*.childNodes[2].firstChild.nodeValue;
		
		/// HERE IS THE PROBLEM
		image* = projectNode.childNodes*.childNodes[3].childNodes[0].firstChild.nodeValue;
		
		
	}
	
	trace(total);
	
	id = setInterval(preloadPic, 100);
} else {
	content = "file not loaded!";
}

```

}  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
[//xmlData.load](https://xmlData.load)(“assets/xml/images.xml”);  
xmlData.load(“assets/xml/test.xml”);  
[/AS]

Help!

---

<div class="post-metadata">

**Author:** ![bombsledder](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bombsledder](https://forum.kirupa.com/u/bombsledder)\
**Post date:** [March 30, 2006, 11:50am UTC](https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821/2 "2006-03-30T11:50:14Z")

</div>

hmm, haven’t worked with xml in a little bit try this,

total = projectNode.length;

---

<div class="post-metadata">

**Author:** ![jimmy\_jazz](https://avatars.discourse-cdn.com/v4/letter/j/dfb087/32.png) [@jimmy\_jazz](https://forum.kirupa.com/u/jimmy_jazz)\
**Post date:** [March 31, 2006, 11:21am UTC](https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821/3 "2006-03-31T11:21:52Z")

</div>

Thanks for the reply bombsledder but that doesnt work.

I can get the total number of \<ProjectImage\> nodes from the xml i posted:

```auto

projectNode = this.firstChild;
totalprojects = projectNode.childNodes.length;

```

Flash returns 2. which is correct.  
But its when I need to get the total number of nodes for each individual project I run into problems.  
I think I will have to do a nested loop within the project loop but cant get flash to trace the correct number. I think it may be looking at the wrong node.

```auto

for (i=0; i<total; i++) {
            
            projectName* = projectNode.childNodes*.childNodes[0].firstChild.nodeValue;
            projectcat* = projectNode.childNodes*.childNodes[1].firstChild.nodeValue;
            description* = projectNode.childNodes*.childNodes[2].firstChild.nodeValue;
            
            /// HERE IS THE PROBLEM 
for (p=0; p<total; p++) {
            image* = projectNode.childNodes*.childNodes[3].childNodes[0].firstChild.nodeValue;
               }
            
        }

```

any ideas?

---

<div class="post-metadata">

**Author:** ![sandeep\_cdac200](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@sandeep\_cdac200](https://forum.kirupa.com/u/sandeep_cdac200)\
**Post date:** [March 31, 2006, 1:52pm UTC](https://forum.kirupa.com/t/xml-and-actionscript-problem-help/183821/4 "2006-03-31T13:52:42Z")

</div>

hi jimmy thumb2:

problem solved use attached code

function fnloadXml(flag:Boolean) {  
if (flag)  
{  
trace(this.firstChild.childNodes[0].childNodes.length);  
for (var i = 0; i\<this.firstChild.childNodes.length; i++)  
{  
for (var j = 0; j\<this.firstChild.childNodes\*.childNodes.length; j++)  
{  
if(j==0)  
{  
trace(“projectName=”+this.firstChild.childNodes\*.childNodes[j].firstChild.nodeValue);  
}  
else if(j==1)  
{  
trace(“projectcat=”+this.firstChild.childNodes\*.childNodes[j].firstChild.nodeValue);  
}  
else if(j==2)  
{  
trace(“projectdesc=”+this.firstChild.childNodes\*.childNodes[j].firstChild.nodeValue);  
}  
else  
{  
for (var k = 0; k\<this.firstChild.childNodes\*.childNodes[j].childNodes.length; k++)  
{  
trace(“Images=”+this.firstChild.childNodes\*.childNodes[j].childNodes[k].firstChild.nodeValue);  
}  
}  
}  
}   
}  
}

with regards  
sandeep(^\_^):
