PDA

View Full Version : Dynamic XML/AS Menu Bar



ANIMAL
February 21st, 2005, 10:38 AM
Hi Kirupians... :bounce:

I need some help with this small project. Basically i'm trying to get the onRollOver function to work with this menu bar. http://www.irl-fca.net/menuxml.htm

This is the source download http://www.irl-fca.net/XMLMenu.zip

For the life of me, I can't get it to work. If someone could please have a look at it. All I want to do is roll over and change the background color of the cell.

I've tried adding it in as a behaviour in the submenu movie clips. But when i try to trace the onRollOver, nothing happens.

Any help will be appricated.

Rgds
ANIMAL


This is how the XML looks.


<?xml version="1.0"?>
<menu>
<item id="Services">
<sub id="This" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="is" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="random" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="stuff" theURL="http://www.your.com (http://www.your.com/)" />
</item>
<item id="About">
<sub id="This" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="is" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="random" theURL="http://www.your.com (http://www.your.com/)" />
<sub id="stuff" theURL="http://www.your.com (http://www.your.com/)" />
</item>
</menu>


This is the ActionScript.


submen = new XML ();
submen.ignoreWhite = true;
function menuOut(xml, movW, mcH, mcW, xpos, ypos){

xMove = 122;
yMove = 135;
xpos = 64;
ypos = 115;
startPos = xpos;
items = xml.firstChild.childNodes;
for(a = 0; a<= items.length-1; a++)
{
subs = xml.firstChild.childNodes[a].childNodes;
iattrib = items[a].attributes;
//trace(iattrib.id); //Will return the name of the current item
//= xml.firstChild.childNodes[a].childNodes[b].childNodes;

item = _root.attachMovie( "menuItem", "item"+a, a);
item.nametxt.text = iattrib.id;
subContain = _root.createEmptyMovieClip("subContain"+a, a+1000);
for(z = 0; z<= subs.length-1; z++)
{
attribs = subs[z].attributes;
sub =_root.subContain.attachMovie( "submenuItem", "sub"+z, z+100);
sub.nametxt.text = attribs.id;
sub._y = (mcH*z)+mcH;
sub.itemUrl = attribs.theURL;
sub.onRelease = function()
{
getURL(this.itemUrl, "_blank");
}
}//END OF FOR B LOOP
//trace(subs);
_root["subContain"+a]._visible=false;
_root["subContain"+a]._x = xpos;
_root["subContain"+a]._y = ypos;
item.num = a;
_root["item"+a].box.subsL = subs.length;
_root["item"+a].box.onRollOver = function()
{
this._height = (this.subsL*mcH)+mcH+8;
}
_root["item"+a].onMouseMove = function()
{
//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);
//Local reference to whether the box is hit or not
this.itemHit = this.box.hitTest(mX, mY);
if(this.itemHit == true)
{
_root["subContain"+this.num]._visible = true;
}else{
_root["subContain"+this.num]._visible = false;
//Snaps our hitbox back to the size of just the main item.
this.box._height = mcH;
}
}
item._x = xpos; //positioning of the subs
item._y = ypos;
//increments the xposition of our whole menu by xmove
xpos += xMove;
//simple if test to see if we will be off the screen
if(xpos >= movW-mcW/2)
{
//increments our whole menu's _y by ymove
ypos += yMove;
//resets our xpos
xpos = startPos;
}
}//END OF FOR A LOOP
}//END OF FUNCTION
submen.onLoad = function(){
menuOut(this, 1200, 28, 122, 75, 15, "menuItem");
}
submen.load ("submen.xml");

luth
February 21st, 2005, 05:59 PM
This is how I would do it.

ANIMAL
February 21st, 2005, 07:38 PM
Luth
You're a gentleman.... :pleased: Thank you very much. This fits the bill perfectly.

ANIMAL

kmjmu
March 18th, 2005, 11:36 AM
is there an easy way to switch the menu from being horizontal to vertical or have the menu expand upward (for example, if the menu was at the bottom of the screen?)