Hi xml expert out there. I need help.
please help.
1.I have a got xml menu but in this submenus are hidden. I dont want them to be hidden.
2. Onclicking the button it should load external swf in main.swf ,_target container.
**
Flash Code**
// universal XML parser, please do not distribute this.
XMLNode.prototype.toObject = function ()
{
var obj = new Object();
var i;
var t;
for (i = 0; i < this.childNodes.length; i++) {
if (this.childNodes*.nodeType == 1) {
if (this.childNodes*.firstChild.nodeType == 3) {
t = new Object();
t.value = this.childNodes*.firstChild.nodeValue;
} else {
t = this.childNodes*.toObject();
}
t.attributes = this.childNodes*.attributes;
if (obj[this.childNodes*.nodeName] == undefined) {
obj[this.childNodes*.nodeName] = t;
} else {
if (!(obj[this.childNodes*.nodeName] instanceof Array)) {
obj[this.childNodes*.nodeName] = [ obj[this.childNodes*.nodeName] ];
}
obj[this.childNodes*.nodeName].push(t);
}
} else {
;
}
}
return obj;
};
ASSetPropFlags(XMLnode, [ "toObject" ], 1);
//
_global.buildMain = function()
{
_global.main_mc = _level0.createEmptyMovieClip("menu_mc",2);
var $i;
for($i=0;$i<xml.menu.main.length;$i++)
{
var $main_btn = main_mc.attachMovie("main","main_"+$i,100+$i); // attach the main menu button...
$main_btn.number = $i; // remember what number button this is...
$main_btn.title.text = xml.menu.main[$i].attributes.name; // grab the name of this button from the XML file...
$main_btn._y = $main_btn._height * $i; // space accordingly.
$main_btn.original_y = $main_btn._y // remember this y coordinate now...
// create some simple mouse states...
$main_btn.onRollOver = function()
{
this.gotoAndStop(2);
};
$main_btn.turnOn = $main_btn.onRollOut = function()
{
this.enabled = 1;
this.gotoAndStop(1)
};
$main_btn.onRelease = function()
{
this.enabled = 0;
this._parent.last_mc.turnOn(); // tell the last btn to play its rollOut state.
this._parent.last_mc = this; // and now remember this as the last_mc pushed.
buildSubNav(this.number); // go to the buildSubNav function with this number and generate the subnav from there.
};
}
};
_global.buildSubNav = function($subnav)
{
var $i;
for($i=0;$i<xml.menu.main.length;$i++)
{
main_mc["main_"+$i]._y = main_mc["main_"+$i].original_y // reset the position of the main menu buttons.
}
var $sub_mc = main_mc.createEmptyMovieClip("subnav",3);
$sub_mc._y = main_mc["main_"+$subnav]._y + main_mc["main_"+$subnav]._height; // position the subnav container below its corresponding button.
var $j;
for($j=0;$j<xml.menu.main[$subnav].sub.length;$j++)
{
var $sub_btn = $sub_mc.attachMovie("subnav","sub_"+$j,200+$j); // attach the sub button...
$sub_btn._y = $sub_btn._height * $j; // space accordingly.
$sub_btn.number = $j // the submenu number...
$sub_btn.title.text = xml.menu.main[$subnav].sub[$j].attributes.name;
// and now similar button functionaly to the main menu above...
$sub_btn.onRollOver = function()
{
this.gotoAndStop(2);
};
$sub_btn.turnOn = $sub_btn.onRollOut = function()
{
this.enabled = 1;
this.gotoAndStop(1)
};
$sub_btn.onRelease = function()
{
this.enabled = 0;
this._parent.last_mc.turnOn(); // tell the last btn to play its rollOut state.
this._parent.last_mc = this; // and now remember this as the last_mc pushed.
// here you can have a getURL or whatever.
};
}
// and finally, we space the main menu buttons below the subnav.
if($subnav < xml.menu.main.length-1 && $sub_mc._height > 1)
{
var $k;
for($k=$subnav+1;$k<xml.menu.main.length;$k++)
{
main_mc["main_"+$k]._y += $sub_mc._height;
}
}
};
// this function loads our XML file and when finished loading converts it to an object (via the XML prototype above).
// that object is then send off to buildMain().
_global.initMenu = function()
{
var $xml = new XML();
$xml.ignoreWhite = 1;
$xml.onLoad = function()
{
_global.xml = $xml.toObject();
buildMain();
};
$xml.load("menu.xml");
};
initMenu(); // launch the program.
xml code:
<?xml version="1.0" ?>
<menu>
<main name="Button 1">
<sub name="Sub 1a" />
<sub name="Sub 2a" />
</main>
<main name="Button 2" />
<main name="Button 3">
<sub name="Sub 1b" />
<sub name="Sub 2b" />
</main>
<main name="Button 4">
<sub name="Sub 1c" />
<sub name="Sub 2c" />
</main>
<main name="Button 5" />
</menu>
Please please help…please