I am creating a dynamic menu based on a simple XML file. I can successfll get my script to parse the XML file and create, place and name button MC’s based on node attribute values.
However, I need each button created to have a seperate onRelease function that is based the node attributes. Basically, each button represents a section you can go to in my flash file on a seperate frame, so when you click the menu button it needs to load a value into a variable from an array which stores all the XML node values in it. This variable is then used to load different XML files throughout the rest of the flash file.
The problem is that my script makes all the menu buttons have the same action based on the last item in the array, so they all go to the same section and load the same content.
Here is what I have so far, maybe it will make a little more sense than my description. Sorry, I have a lot of traces in there right now to try and figure out what’s going on.
Any help would be appreciated, thanks.
_global.currentCountry;
_global.currentUnit;
_global.units_list = [];
_global.countries_list = [];
_global.totalUnits;
_global.curr_item = [];
var counter = 0;
var countries_xml:XML = new XML();
countries_xml.ignoreWhite = true;
countries_xml.onLoad = function(success) {
if (success) {
trace("Country XML Loaded");
var countryNodes = countries_xml.firstChild;
_global.totalUnits = countryNodes.childNodes.length;
trace("Total Units = "+_global.totalUnits);
for (i=0; i<_global.totalUnits; i++) {
counter = i;
trace("Node Number = "+counter);
_global.countries_list[counter] = countryNodes.childNodes[counter].attributes.country;
trace("_global.countries_list["+counter+"] = "+_global.countries_list[counter]);
_global.units_list[counter] = countryNodes.childNodes[counter].attributes.name;
trace("_global.units_list["+counter+"] = "+_global.units_list[counter]);
_global.curr_item[counter] = attachMovie("Unit_Menu_MC", "Unit_Menu_MC_"+_global.units_list[counter].split(" ").join("_"), counter, {_x:64, _y:(20*counter)+376});
trace("curr_item ["+counter+"] = "+curr_item[counter]);
_global.curr_item[counter].onRelease = function() {
trace(_global.curr_item[counter]);
trace("Selected Node Number "+counter);
_global.currentUnit = _global.units_list[counter];
trace(this+" _global.currentUnit = "+_global.currentUnit);
_global.currentCountry = _global.countries_list[counter];
trace(this+" _global.currentCountry = "+_global.currentCountry);
for (j=0; j<_global.totalUnits; j++) {
trace("j = "+j);
removeMovieClip("_root.Unit_Menu_MC_"+_global.units_list[j].split(" ").join("_"));
trace("_root.Unit_Menu_MC_"+_global.units_list[j].split(" ").join("_")+" Removed");
}
_root.gotoAndPlay('Music Overview');
};
_global.curr_item[counter].Unit_Menu_txt.text = _global.units_list[counter];
}
}
};
countries_xml.load("Countries/Data/Country_Menu.xml");