hi,
i am stuck with this.
/*some variables*/
var holder_mc:MovieClip;
var menuArray:Array = new Array();
var subMenuArray:Array = new Array();
/*functions*/
function generateMenu(x, y, name,depth, thisArray) {
trace(menuArray.length);
var curr_item:MovieClip;
var curr_menu = holder_mc.createEmptyMovieClip(name, depth);
for (i=0; i<thisArray.length; i++) {
curr_item = curr_menu.attachMovie("menuItem", "item"+i, i);
curr_item._x = holder_mc._x;
curr_item._y = holder_mc._y+i*40;
curr_item.menuText.autoSize = true;
curr_item.menuText.multiline = false;
curr_item.menuText.condenseWhite = true;
curr_item.menuText.text = thisArray*.name;
//trace(Math.floor(curr_item.menuText._width));
curr_item.menuItemBG_mc._width = Math.floor(curr_item.menuText._width)+15;
curr_item.onRollOver = over;
curr_item.onRollOut = out;
curr_item.gotoURL = thisArray*.gotoURL;
curr_item.onRelease = goto;
}
}
function initXML() {
var xmlwebsiteContent:XML = new XML();
xmlwebsiteContent.ignoreWhite = true;
xmlwebsiteContent.onLoad = loadWebsiteContent;
xmlwebsiteContent.load("xml/menu.xml");
}
function loadWebsiteContent(succes) {
if (succes) {
var xmlNode = this.firstChild.childNodes;
for (var i = 0; i<xmlNode.length; i++) {
var websiteItems = xmlNode*;
//to do if is the menu node
if (websiteItems.nodeName == 'menu') {
for (var j:Number = 0; j<websiteItems.childNodes.length; j++) {
//we need to create a submenu
var tempSubmenu:Array = new Array();
tempSubmenu.name= websiteItems.childNodes[j].attributes.name;
tempSubmenu.gotoURL = websiteItems.childNodes[j].attributes.gotoURL;
submenuArray.push(tempSubmenu);
generateMenu(0, this._y, "submenu", this.getNextHighestDepth(), submenuArray);
}
}
if(websiteItems.nodeName == 'item') {
var tempMenu:Array = new Array();
tempMenu.gotoURL = websiteItems.attributes.gotoURL;
tempMenu.name = websiteItems.attributes.name;
menuArray.push(tempMenu);
trace(menuArray);
}
}
generateMenu(0, 0, "menu", this.getNextHighestDepth(), menuArray);
} else {
content = "file not loaded!";
}
}
initXML();
the xml file looks like
<?xml version="1.0"?>
<menu name="links">
<menu name="macromedia">
<item name="flash" gotoURL="http://www.macromedia.com/software/flash"/>
<item name="dreamweaver" gotoURL="http://www.macromedia.com/software/dreamweaver"/>
<item name="fireworks" gotoURL="http://www.macromedia.com/software/fireworks"/>
</menu>
<menu name="kirupa">
<item name="home" gotoURL="http://www.kirupa.com"/>
<item name="forums" gotoURL="http://www.kirupaforum.com/forums/index.php"/>
<menu name="tutorials">
<item name="actionscript" gotoURL="http://www.kirupa.com/developer/actionscript/index.htm"/>
<item name="photoshop" gotoURL=" http://www.kirupa.com/photoshop/index.htm"/>
<item name="web" gotoURL="http://www.kirupa.com/web/index.htm"/>
</menu>
</menu>
<item name="google" gotoURL"="http://www.google.com"/>
</menu>
Only the item node is visible, i like to make a vertical menu where the submenu’s are invisible at first. and onRelease/onRollOver are visible and the menu becomes higher depending on the # of sub items
Should i create 2 seperate arrays (menu &submenu) or not??
Any tips, links?
regards