Alright, I’ve been tasked to build a menu system similar to the one on 2Advanced V5. I know, I know, don’t mess with copying peoples’ stuff, but my arm’s being twisted to do so, by the management. :wt:
I’ve started with Kirupa’s XML menu, modified the XML to my liking, and have added some sliding code in there. I’m having a hard time with:
- Getting the sliding code to interact with the submenus.
- I’ve got no idea how to adjust the submenus so they don’t scroll too fast or too slow.
Any help you could give would be… helpful.
EDIT: All I need is for each submenu to be scrollable, and not scroll too fast, based on how many buttons are in there. XML source can be set to the XML example in Kirupa’s tutorials.
The FLA is attached, and here’s the Actionscript:
// generates a list of menu items (effectively one menu)
// given the inputted parameters. This makes the main menu
// as well as any of the submenus
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
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;
curr_item.jpegURL = curr_node.attributes.jpegURL;
// item submenu behavior for rollover event
if (node_xml.childNodes*.nodeName == "menu"){
// open a submenu
curr_item.node_xml = curr_node;
curr_item.onRollOver = curr_item.onDragOver = function(){
var x = this._x + this._width + 10;
GenerateMenu(curr_menu, "submenu_mc", x, y, 1000, this.node_xml);
//This is the part that animates the generated menu, vertically
while (curr_menu.submenu_mc.onDragOver) {
setProperty("curr_menu.submenu_mc", _y, getProperty("", _y)*-.35);
if (getProperty ("", _y)>=200) {
setProperty("curr_menu.submenu_mc", _y, "150");
}
if (getProperty ("", _y)<=0) {
setProperty("curr_menu.submenu_mc", _y, "0");
}
}
//over state for items
this.background.gotoAndPlay('openitem');
};
}else{ // nodeName == "item"
// close existing submenu
curr_item.onRollOver = curr_item.onDragOver = function(){
curr_menu.submenu_mc.removeMovieClip();
// run movie to over state
this.background.gotoAndPlay('openitem');
};
}
curr_item.onRollOut = curr_item.onDragOut = function(){
// run close menu anim
this.background.gotoAndPlay('closeitem');
};
// any item, menu opening or not can have actions
curr_item.onRelease = function(){
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);
// close only submenus if visible durring a mouseup
// this main menu (mainmenu_mc) will remain
mainmenu_mc.onMouseUp = function(){
if (mainmenu_mc.submenu_mc && !mainmenu_mc.hitTest(_root._xmouse, _root._ymouse, true)){
CloseSubmenus();
}
};
};
// closes all submenus by removing the submenu_mc
// in the main menu (if it exists)
CloseSubmenus = function(){
mainmenu_mc.submenu_mc.removeMovieClip();
};
// 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("[menucontent.xml](http://www.redzcomfort.com/menucontent.xml)");