Hey, I’ve been following the Introduction to XML article and started playing around with the Squirrel Finder example, my aim was to make an XML menu which would simply load a URL in a new window. This would (hopefully) allow me to add downloads to my site through XML. I thought I’d clocked it and finally understood what was going on, but I seem to have lost and confused myself with it. Now I’m really scratching my head, cause I can’t see what’s wrong.
I changed the tutorial example to use attributes instead of nodes, and found things working out quite nicely, but I just noticed I’m having issues with my URLs.
For some strange reason, no matter which button I click on, I always get sent to the last URL that was loaded from the XML file, instead of the correct one. I’m hoping someone can help, because I’ve been working through this for the best part of a day and I’m starting to lose hope.
Here’s the code:
// define basic variables for setting up the menu
var item_spacing = 54; // 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;
for (var i=0; i<items.length; i++) {
if (items*.attributes.type == "client_checkup") {
// create variables for our elements
var client = items*.attributes.client;
var title = items*.attributes.title;
var urls = items*.attributes.urls;
var item_mc = menu_mc.attachMovie("menu_item","item"+item_count, item_count);
item_mc._y = item_count * item_spacing;
item_count++;
item_mc.client.text = items*.attributes.client;
item_mc.title.text = items*.attributes.title;
// set the onRelease of the item button to the DisplayInfo function
item_mc.main_btn.onRelease = function(){
getURL(urls, "_blank");
}
}
}
}
// manage XML
// create new XML object instance, remembering to ignore white space
var test_xml = new XML();
test_xml.ignoreWhite = true;
// define an onLoad to create our location menu when the XML has successfully loaded.
test_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!
test_xml.load("test.xml");
Thanks in advance to anyone that can shed some light on my error, I can only assume it’s obvious as I thought it was all working earlier today.