# Nested loops (XML) for values

**URL:** <https://forum.kirupa.com/t/nested-loops-xml-for-values/168583>\
**Category:** flash\
**Created:** [November 8, 2005, 2:58pm UTC](https://forum.kirupa.com/t/nested-loops-xml-for-values/168583 "2005-11-08T14:58:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bchalker](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/bchalker/32/441_2.png) [@bchalker](https://forum.kirupa.com/u/bchalker)\
**Post date:** [November 8, 2005, 2:58pm UTC](https://forum.kirupa.com/t/nested-loops-xml-for-values/168583/1 "2005-11-08T14:58:06Z")

</div>

I have a project that needs to take the following XML:

* * *

\<?xml version=“1.0” encoding=“iso-8859-1”?\>  
\<adList\>  
\<adBlock id=“0”\>   
\<ad id=“thisNumber0” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber1” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\</adBlock\>  
\<adBlock id=“1”\>  
\<ad id=“thisNumber0” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber1” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber2” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\</adBlock\>  
\<adBlock id=“2”\>  
\<ad id=“thisNumber0” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber1” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber2” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\</adBlock\>  
\<adBlock id=“3”\>  
\<ad id=“thisNumber0” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber1” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber2” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\<ad id=“thisNumber3” imageFile=“thisAd.jpg” videoFile=“video.flv” couponImage=“this.bmp”/\>  
\</adBlock\>  
…  
\</adList\>

* * *

I am needing to loop through using an array and assign the values to a set of ten MC\_buttons (labeled adBlock0-adBlock9).

My AS:  
contentXML = new XML();  
contentXML.ignoreWhite = true;  
contentXML.onLoad = function(success){  
if (success){  
parseThis();  
trace(“Loaded”)  
;  
}  
}  
contentXML.load(“contentFile.xml”)

function parseThis(){  
var adListingContents = contentXML.firstChild.childNodes;  
for (var i=0; i\<adListingContents.length; i++)  
{  
for(k=0;k\<12;k++){  
this[“adBlock”+k].thisPath=adListingContents[k].attributes.id  
this[“adBlock”+k].onRelease = function(){  
trace(this.thisPath)  
}  
var adListing = adListingContents\*;  
var ads = adListing.childNodes;  
for (var j=0; j\<ads.length; j++)  
{  
var ad = ads[j];  
}  
}   
}  
}

//I need the following assigned from the \<ad\> childnodes of each \<adBlock\> section in the XML file :  
//this[“adBlock”+k].adID  
//this[“adBlock”+k].imageFile  
//this[“adBlock”+k].videoFile  
//this[“adBlock”+k].couponImage

I have no problem reading and assigning the “thisPath”, but I’m not sure how to then assign the adID/imageFile/… with the other loop.

I’ve read through the Senocular tut (it’s great), but it’s starting to overwhelm me.

I understand the single/XML for assigning content, but I don’t usually use it to this extent.

Any ideas?

Thanks
