I’m trying to make a submenu using an external xml file. It loads but I can’t make a submenu appearing while I’m on the main menu one.
here’s my code:
var submenu = new XML();
submenu.ignoreWhite = true;
submenu.load(_root.chemin+“menu2.xml”);
submenu.onLoad = function() {
genererSousMenu(this, 1200, 25, 122, 75, 15, “menuItem”);
};
function genererSousMenu(xml, movW, mcH, mcW, xpos, ypos) {
var xMove = 122;
var yMove = 135;
var xpos = 62;
var ypos = 310;
var startPos = xpos; // start position
var racine = xml.firstChild;
var nb_elements = racine.childNodes.length;
for(a=0; a<nb_elements; a++)
{
var main = racine.childNodes[a].attributes;
var subs = racine.childNodes[a].childNodes;
// On va chercher main MC etant les options du menu principal
var item = _root.attachMovie("menuItem", "item"+a, a);
item.nom_txt.text = main.id;
// Submenu things begins...
var subContain = _root.createEmptyMovieClip("subContain"+a, a+1000);
// Submenu
for(z=0; z<subs.length; z++)
{
attribs = subs[z].attributes;
sub = subContain.attachMovie( "submenuItem", "sub"+z, z+100);
//trace("sub "+attribs.id);
sub.nom_txt.text = attribs.id;
//trace("mcHx= "+mcH);
sub._y = (mcH*z)+mcH;
//trace("mcH: " +(mcH*z)+mcH);
sub.itemUrl = attribs.theURL;
sub.onRollOver = function() {
this.gotoAndStop(2);
}
sub.onRollOut = function() {
this.gotoAndStop(1);
}
sub.onRelease = function()
{
getURL(this.itemUrl, "_blank");
}
} //END OF FOR B LOOP
_root["subContain"+a]._visible = false;
_root["subContain"+a]._x = xpos;
//trace("Ypos:"+ypos);
_root["subContain"+a]._y = 85; //ypos;
item.num = a;
_root["item"+a].box.subsL = subs.length;
_root["item"+a].box.onRollOver = function()
{
//trace("Height: " + (this.subsL*mcH)+mcH+8);
this._height = (this.subsL*mcH)+mcH+8;
}
_root["item"+a].onMouseMove = function()
{
//Reference variables to the mouse coords
var mY = _root._ymouse;
var mX = _root._xmouse;
//trace("mX:"+mX +"mY:"+mY);
//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);
// Cas ou la souris est sur un des boutons, on ouvre sub menu
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
}