# Xml menu load multiple xml

**URL:** <https://forum.kirupa.com/t/xml-menu-load-multiple-xml/200344>\
**Category:** Uncategorized\
**Created:** [September 11, 2006, 4:00pm UTC](https://forum.kirupa.com/t/xml-menu-load-multiple-xml/200344 "2006-09-11T16:00:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wakatanka](https://avatars.discourse-cdn.com/v4/letter/w/8797f3/32.png) [@wakatanka](https://forum.kirupa.com/u/wakatanka)\
**Post date:** [September 11, 2006, 4:00pm UTC](https://forum.kirupa.com/t/xml-menu-load-multiple-xml/200344/1 "2006-09-11T16:00:40Z")

</div>

I’ve made an xml menu, following the squirrel tutorial, what i wanna do more, is that  
when i click on a menu item, this will pass to actionscript the name of the xml file to load for the image gallery. I have a file xml for the menu:

\<menu\>  
\<gallery\>  
\<item\> galleria 1  
\<image\>image1.xml\</image\>  
\</item\>  
\<item\> galleria 2  
\<image\>image2.xml\</image\>  
\</item\>  
\<item\> galleria 3  
\<image\>image3.xml\</image\>  
\</item\>  
\</gallery\>  
\</menu\>

and three other file for the image: image1.xml, image2.xml image3.xml

this is my as code:

stop();  
// carico il file xml delle immagini  
function loadXML(loaded) {  
// se il carimento va a buon fine  
if (loaded) {  
// questo è la prima immagine del file xml  
xmlNode = this.firstChild;  
// queste 2 variabili contengono gli array delle immagini e delle descrizioni nel mio file XML  
image = [];  
description = [];  
// questa variabile è il totale di tutti i nodi-figli del mio file xml, cioè il numero totale di immagini  
total = xmlNode.childNodes.length;  
// con questo ciclo for assegno ogni nome di immagine e descrizione agli array delle mie variabili image e description, fino a  
// raggiungere il totale delle immagini (variabile TOTAL)  
for (i=0; i\<total; i++) {  
image\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
description\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
}  
firstImage();  
// se il caricamento non va a buon fine avvertimi  
} else {  
trace(“file not loaded!”);  
}  
}  
// assegno la variabile xmlData al mio oggetto XML che sto creando  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“images1.xml”);  
/////////////////////////////////////

listen = new Object();  
listen.onKeyDown = function() {  
if (Key.getCode() == Key.LEFT) {  
prevImage();  
} else if (Key.getCode() == Key.RIGHT) {  
nextImage();  
}  
};  
Key.addListener(listen);  
previous\_btn.onRelease = function() {  
prevImage();  
};  
next\_btn.onRelease = function() {  
nextImage();  
};  
/////////////////////////////////////  
p = 0;  
this.onEnterFrame = function() {  
filesize = picture.getBytesTotal();  
loaded = picture.getBytesLoaded();  
preloader.\_visible = true;  
if (loaded != filesize) {  
preloader.preload\_bar.\_xscale = 100\*loaded/filesize;  
} else {  
preloader.\_visible = false;  
picture.\_x = 450-picture.\_width/2;  
picture.\_y = 300-picture.\_height/2;  
if (picture.\_alpha\<100) {  
picture.\_alpha += 10;  
}  
}  
};  
function nextImage() {  
if (p\<(total-1)) {  
p++;  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
}  
function prevImage() {  
if (p\>0) {  
p–;  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
function firstImage() {  
if (loaded == filesize) {  
picture.\_x = (stageWidth-mcWidth)/2;  
picture.\_y = (stageHeight-mcHeight)/2;  
picture.\_alpha = 0;  
picture.loadMovie(image[0], 1);

```
	desc_txt.text = description[0];
	picture_num();
}

```

}  
//  
//  
//  
//  
//  
// define basic variables for setting up the menu  
var item\_spacing = 28; // how far menu items are spaced veritcally  
var item\_count = 0; // counts menu items as they are added from the XML

// CreateMenu creates a menu based on the XML object passed.  
// It loops through all the items with a for loop adding clips to the menu\_mc  
// movieclip on the timeline, defining the appropriate text where needed  
function CreateMenu(menu\_xml){  
// start with the first item in the XML  
var items = menu\_xml.firstChild.firstChild.childNodes; // menu -\> menuitems -\> child nodes array  
for (var i=0; i\<items.length; i++) {

```
		var gallery = items*.firstChild; // same as items*.childNodes[0]
		var image = items*.childNodes[1]; // second child node
		
		// Create a menu item movie clip in the menu_mc instance on the main timeline
		// for each item element offsetting each additional further down the screen
		var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
		item_mc._y = item_count * item_spacing;
		item_count++;
		

		item_mc.gallery_txt.text = gallery.nodeValue;
		
		// set the onRelease of the item button to the DisplayInfo function
	
		item_mc.main_btn.onRelease = ?????
		}
	
}

```

}

// manage XML  
// create new XML object instance, remembering to ignore white space  
var gallery\_xml = new XML();  
gallery\_xml.ignoreWhite = true;  
// define an onLoad to create our location menu when the XML has successfully loaded.  
gallery\_xml.onLoad = function(success){  
if (success) CreateMenu(this);  
else trace(“Error loading XML file”); // no success? trace error (wont be seen on web)  
}  
// load the xml file!  
gallery\_xml.load(“gallery.xml”);

thank you for your help
