I am making a menu that refrences data from an XML file to make the menu. There are two parts to the menu.
Part 1 - A movieclip called menuitem is created for each XML node that is a Menu. This code is placed on Frame 1 of the _root timeline.
// generates a list of menu items (effectively one menu)
// given the inputted parameters. This makes the main menu
GenerateMenu = function(container, name, x, y, depth, node_xml) {
// variable declarations
/*var curr_node;*/
var curr_item;
var curr_menu = container.createEmptyMovieClip(name, depth);
// for all items or XML nodes (items and menus)
// within this node_xml passed for this menu
for (var i=0; i<node_xml.childNodes.length; i++) {
// movieclip for each menu item
curr_item = curr_menu.attachMovie("menuitem","item"+i+"_mc", i);
curr_item._x = x;
curr_item._y = y + i*curr_item._height;
curr_item.trackAsMenu = true;
// item properties assigned from XML
_global.curr_node = node_xml.childNodes*;
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.name.text = curr_node.attributes.name;
// any item, menu opening or not can have actions
/*curr_item.onRelease = function(){
_level0.menuitem.play();
Actions[this.action](this.variables);
CloseSubmenus();
};*/
} // end for loop
};
// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
// generate a menu list
GenerateMenu(this, "mainmenu_mc", x, y, depth, menu_xml.firstChild);
};
// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed
Actions = Object();
Actions.gotoURL = function(urlVar){
getURL(urlVar, "_blank");
};
Actions.message = function(msg){
message_txt.text = msg;
};
Actions.newMenu = function(menuxml){
menu_xml.load(menuxml);
};
// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
// create main menu after successful loading of XML
if (ok){
CreateMainMenu(10, 10, 0, this);
message_txt.text = "message area";
}else{
message_txt.text = "error: XML not successfully loaded";
}
};
// load first XML menu
menu_xml.load("gallery.xml");
Part 2 - There is a button within the menuitem_mc that uses play(); to play the menuitem_mc until frame 30 where a stop(); action stops the timeline. During the 30 frames a Shape Tween extends the background of menuitem_mc. On another Blank Keyframe on frame 30 there is more actionscript that is supposed to create a movieclip called “title” for each item in the XML.
// generates a list of menu items (effectively one menu)
// given the inputted parameters. This makes the main menu
GenerateMenu = function(container, name, x, y, depth, node_xml) {
// variable declarations
var curr_node;
var curr_item;
var curr_menu = container.createEmptyMovieClip(name, depth);
// for all items or XML nodes (items and menus)
// within this node_xml passed for this menu
for (var i=0; i<_global.curr_node.childNodes.length; i++) {
// movieclip for each menu item
curr_item = curr_menu.attachMovie("title","item"+i+"_mc", i);
curr_item._x = x;
curr_item._y = y + i*curr_item._height;
curr_item.trackAsMenu = true;
// item properties assigned from XML
curr_node = _global.curr_node.childNodes*;
curr_item.action = curr_node.attributes.action;
curr_item.variables = curr_node.attributes.variables;
curr_item.name.text = curr_node.attributes.name;
} // end for loop
};
// create the main menu, this will be constantly visible
CreateMainMenu = function(x, y, depth, menu_xml){
// generate a menu list
GenerateMenu(this, "title_mc", x, y, depth, menu_xml.firstChild);
};
// This actions object handles methods for actions
// defined by the XML called when a menu item is pressed
Actions = Object();
Actions.gotoURL = function(urlVar){
getURL(urlVar, "_blank");
};
Actions.message = function(msg){
message_txt.text = msg;
};
Actions.newMenu = function(menuxml){
menu_xml.load(menuxml);
};
// load XML, when done, run CreateMainMenu to interpret it
menu_xml = new XML();
menu_xml.ignoreWhite = true;
menu_xml.onLoad = function(ok){
// create main menu after successful loading of XML
if (ok){
CreateMainMenu(5, 40, 2, this);
message_txt.text = "message area";
}else{
trace("error: XML not successfully loaded");
}
};
// load first XML menu
menu_xml.load("gallery.xml");
I am unsure how to make Part 2 reference the childnodes fo the orginal menu node. I have tried to use _global to tell Part 2 that we are still talking about a certain node reference in Part1, but to no avail.
For example:
If the XML were
<?xml version="1.0"?>
<menu name="Menu">
<menu name="Menu1">
<item name="item1" action="message" variables="here is a menu of useful links"/>
<item name="item2" action="message" variables="here is a menu of useful links"/>
</menu>
<menu name="Menu2">
<item name="item3" action="message" variables="here is a menu of useful links"/>
<item name="item4" action="message" variables="here is a menu of useful links"/>
<item name="item5" action="message" variables="here is a menu of useful links"/>
</menu>
</menu>
Then Part 1 would show Menu1 and Menu2. If you click Menu1 then Part 2 would only show item1 and item2. Whereas if you were to click Menu2 you would only see item3, item4, and item5.
I am using a tutorial on dropdown menus from Kirupa to help me, but it isnt designed specifically for what i’m doing (well duh lol). The link to that tuorial is at http://www.kirupa.com/developer/actionscript/xml_dropdown_menu.htm
I have attached the .zip containing the .FLA and .XML in case you need it.
Any help is greatly appreciated.