Hello,
I’ve got the action script below to load an xml file with menu info. Everything at this point works, the menu drops down, everything is great. I would like to make it so the menu slides down, instead of just appears. I’m unsure of how to do this because the movie clip that contains the sub menus (subContain) is dynamically created.
Any ideas on how I can accomplish it?
Here is the actionscript:
//MENU CONFIG
cfg_XMLFile = "submen.xml"; //XML Filename
cfg_xMove = 125; //Menu Header x-axis move, Typical = width of movie clip
cfg_mcHeight = 25; //Height of Menu Header movie clip
cfg_mcWidth = 125; //Width of Menu Header movie clip
cfg_xStartPos = 75; //x coordinate of first Menu Header Clip
cfg_yStartPos = 15; //y coordinate of first Menu Header Clip
//END CONFIG
//####################################################
//START CODE
//XML Setup
menu = new XML();
menu.ignoreWhite = true;
menu.load(cfg_XMLFile); //Set xml file name in config section
//Function that assembles the menu
function menuCreate(xml, mcH, mcW, xpos, ypos, xMove){
//###MAIN MENU ITEMS
items = xml.firstChild.childNodes; //Gets menu headers from xml and puts into array "items"
for(a = 0; a<= items.length-1; a++){ //loop from 0 to number of items in array "items"
iattrib = items[a].attributes; //Collect current menu attributes into object
item = _root.attachMovie( "menuItem", "item"+a, a); //Use movie clip "menuItem" to create menu header
item.nametxt.text = iattrib.id; //Set dynamic text box "nametxt" of movie clip "menuItem" to menu name
//###SUB MENU ITEMS - CREATION
subs = xml.firstChild.childNodes[a].childNodes; //Get submenu items for array item #a and send to array "subs"
subContain = _root.createEmptyMovieClip("subContain"+a, a+1000); //Create movie clip to store all sub menu clips
for(z = 0; z<= subs.length-1; z++){ //loop from 0 to number of sub menu items for current main menu item
attribs = subs[z].attributes; //Set attribute items of sub menu to object "attribs"
sub =_root.subContain.attachMovie( "menuItem", "sub"+z, z+100); //Use movie clip "menuItem" to create submenu item
sub.nametxt.text = attribs.id; //Set dynamic text box "nametxt" of movie clip "menuItem" to menu name
sub._y = (mcH*z)+mcH; //Set the y position of the submenu item
sub.itemUrl = attribs.theURL //Set URL of submenu item
sub.onRelease = function(){ //If submenu item is clicked, open the URL
getURL(this.itemUrl, "_blank"); //Open URL in new window
}
}//CLOSE SUB MENU LOOP
//###SUB MENU ITEMS - OPERATION
//NOTE: Remember, subContain# contains all submenu movie clips, think of it as a drawer for multiple items
//x and y will be the same as the main menu item
_root["subContain"+a]._visible=false; //Hide submenu movie clip "subContain#"
_root["subContain"+a]._x = xpos; //Set x coordinate of "subContain#"
_root["subContain"+a]._y = ypos; //Set y coordinate of "subContain#"
item.num = a;
_root["item"+a].box.subsL = subs.length;
_root["item"+a].box.onRollOver = function(){
this._height = (this.subsL*mcH)+mcH+8;
}
//###MENU OPERATION, MOUSE TRACKING
_root["item"+a].onMouseMove = function(){ //When the mouse moves, track it
//Reference variables to the mouse coords
mY = _root._ymouse;
mX = _root._xmouse;
//Local reference to whether the subContain is hit or not
this.subHit = _root["subContain"+this.num].hitTest(mX, mY);
//SUBMENU APPEAR/DISAPPEAR
this.itemHit = this.box.hitTest(mX, mY); //If mouse is over "box" of clip "menuItem", show submenu
//NOTE: "box" expands to cover header and submenu items as long as mouse is moving over "box" the submenu stays open, else it closes
if(this.itemHit == true){
_root["subContain"+this.num]._visible = true;
}else{ //Mouse not over "box" anymore, hide submenu
_root["subContain"+this.num]._visible = false;
this.box._height = mcH; //resize "box" back to just cover menu header
}
}//CLOSE MOUSE TRACKING
//Place the menu item
item._x = xpos;
item._y = ypos;
xpos += xMove; //Move xpos over for next menu item (So they aren't on top of each other)
}//CLOSE MENU HEADER LOOP
}//CLOSE menuCreate FUNCTION
menu.onLoad = function(){
menuCreate(this, cfg_mcHeight, cfg_mcWidth, cfg_xStartPos, cfg_yStartPos, cfg_xMove, "menuItem");
}
The project is also attached.
Thank you!