PDA

View Full Version : Attaching XML to menuBar component


pixelcrate
02-09-2004, 03:41 AM
I'm having trouble attaching xml files to the menuBar component in Flash MX2004 Professional. I seem to be able to attach the xml file to the menu using the inbuilt help panel inside Flash MX2004 Pro. However, I am stubbed as to getting the actionscript to read and format the xml file into the main sections and subsections of the menu. Also once beyond getting the menu to display the sections and subsections I can't work out how to link to another *.swf file from the menu, load it into a blank movie clip/loader component or get it to jump to a frame/frame label.

Anyone got any helpful hints or has anyone got a tutorial that could show me.

Any help would be great.

Cheers,

PIXELCRATE

dr.swank
04-12-2004, 10:15 AM
I will not rant about the lack of useful info from MM at this point. The way to access the dynamic menus that are created via the dataProvider property of the menuBar class is by adding a listener object to the internal array of menu's that each menuBar maintains. it is called "__menus" (with 2 underscores)...

var myMenuBarDP = new XML();
myMenuBarDP.load("http://pathtoxmlfile/menufile.xml");
myMenuBarDP.onLoad = function(success) {
if (success)
{
myMenuBar.labelField = "name";
myMenuBar.dataProvider = myMenuBarDP.firstChild;
for (var m in myMenuBar.__menus)
{
trace(typeof myMenuBar.__menus[m]);
myMenuBar.__menus[m].addEventListener("change", Lobj);
myMenuBar.__menus[m].addEventListener("menuShow", Lobj);

}
} else
{
trace("error loading XML file");
}
};
Lobj = new Object();
Lobj.change = function(evt) {
/*trace("listen"+evt.target);

for(var e in evt.target.rows){
trace(e+" : "+evt.target.rows[e].cll.text)
}
for(var e in evt){
trace(e+" : "+evt[e])
}*/
trace(evt.menuItem.attributes.name);
Lobj.menuShow=function(evt){
trace(evt.menuItem.attributes.name);
/*for(var e in evt){
trace(e+" : "+evt[e])
}*/
}
};

try this code for size. Unlike a regular MMcomponent listener eventObject, the menuBar passes a copy of the XMLNode to the listener. Thus I address the info in the 'evt' via the XML opperators. Quite annoying to have toi do it this way, but at least there is hope....

cheers, Doc