My brain is sizzling. I can smell it!
I’m trying to figure our how to process the following XML structure:
<?xml version=“1.0”?>
<links>
<item type=“discussion”>
<title>My Wheels are round</title>
<link>http://www.esc.edu</link>
</item>
<item type=“schedule”>
<title>Saratoga New York</title>
<link>http://www.esc.edu</link>
</item>
<item type=“assignments”>
<title>Ride the Bus</title>
<link>http://www.esc.edu</link>
</item>
</links>
so that I have categories of links designated by item type: assignments, schedule, discussion. These links are displayed in a vertical navigation of buttons that take to the specified link. However, each category does not appear unless the user clicks on a button to make the category’s links appear.
I’ve managed to get this far, but hit a major roadblock on the logic for the next step and suggestions are greatly appreciated!
// 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 ProcessXML(menu_xml){
// start with the first item in the XML
var items = menu_xml.firstChild.childNodes;
for (var i=0; i<items.length; i++) {
// only continue if the type of this item is a DISCUSSION
if (items*.attributes.type == “discussion”) {
// create variables for our element
var ftitle = items*.firstChild; // same as items*.childNodes[0]
var link = items*.childNodes[1]; // second child node
// Create a menu item movie clip in the mcNavigation instance on the main timeline
// for each item element offsetting each additional further down the screen
var mcLink = mcNavigation.attachMovie("menuitem","item"+item_count, item_count);
mcLink._y = item_count * item_spacing;
item_count++;
// assign text using nodeValue to get the text
// from the text nodes and CDATA sections
mcLink.mcText.text = ftitle.firstChild.nodeValue;
mcLink.mcButton.location_text = link.firstChild.nodeValue;
// set the onRelease of the item button to the DisplayInfo function
mcLink.mcButton.onRelease = DisplayInfo;
}
}
}
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success:Boolean) {
if (success) {
ProcessXML(this);
}
else {
trace(“Error loading XML file”); // no success? trace error (wont be seen on web)
}
}
myXML.load(“navigation.xml”);