XML and Actionscript Problem - Help!

Hi

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


<?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(“assets/xml/images.xml”);
xmlData.load(“assets/xml/test.xml”);
[/AS]

Help!

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

total = projectNode.length;

Thanks for the reply bombsledder but that doesnt work.

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


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.


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?

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(^_^):