Hi everyone,
Hopefully this posting won't affect the layout of the code in this
message. If the layout does get all messed up again can someone let me
know why that might be when posting a message? My problem is described
again here.
I have a problem with my MenuBar in the fact that I can get
setMenuItemSelected to work. When items on the menu get a tick, I need
them them to stay that way to show a visited state within the menu. I
can't seem to address the correct item in the menu when using
setMenuItemSelected and so the items just untick when selected again.
Many thanks in advance to anyone who can help me fix this problem as
I've spent far too long trying to sort it out. Here's my code, the menu
uses and xml file to populate and everything else works fine:
// If we import the controls, we can then use createClassObject, as seen
// a few lines down, to create a MenuBar without actually having to
place
// a MenuBar component on the stage.
import mx.controls.MenuBar;
// ====================================================================
// Create a MenuBar object on the screen
this.createClassObject(mx.controls.MenuBar, "xmlMenuBar", 25);
// XML
var myDP_xml:XML;
// Listener object
var fileListener:Object;
// ====================================================================
// Set up tab index etc.
xmlMenuBar.tabEnabled = true;
xmlMenuBar.tabIndex = 1;
// ====================================================================
//define styles for the ComboBox component
xmlMenuBar.setStyle("backgroundColor", 0xD8CCB6);
//xmlMenuBar.setStyle("alternatingRowColors", [0xE9E1D6, 0xCEBEA6]);
xmlMenuBar.setStyle("color", 0x666666);
xmlMenuBar.setStyle("embedFonts", false);
xmlMenuBar.setStyle("textAlign", "left");
//xmlMenuBar.setStyle("fontStyle", "italic");
// ====================================================================
myDP_xml = new XML();
myDP_xml.ignoreWhite = true;
myDP_xml.onLoad = function(success:Boolean) {
if (success) {
// Set the size and position of the menu using XML values
xmlMenuBar._height =
myDP_xml.firstChild.nextSibling.attributes.menuHeight;
xmlMenuBar._width =
myDP_xml.firstChild.nextSibling.attributes.menuWidth;
xmlMenuBar._x = myDP_xml.firstChild.nextSibling.attributes.xPos;
xmlMenuBar._y = myDP_xml.firstChild.nextSibling.attributes.yPos;
//
// set some of the style values from XML data
xmlMenuBar.setStyle("fontFamily",
myDP_xml.firstChild.nextSibling.attributes.menuFont);
xmlMenuBar.setStyle("fontSize",
myDP_xml.firstChild.nextSibling.attributes.menuFontSize);
xmlMenuBar.setStyle("themeColor",
myDP_xml.firstChild.nextSibling.attributes.menuColour);
//
// populate the menu with the XML values
xmlMenuBar.dataProvider = myDP_xml.firstChild;
//trace(myDP_xml.firstChild);
} else {
trace("error loading XML file");
}
};
myDP_xml.load("menuBarXML.xml");
//
// The listenered for the file menu (and submenus)
fileListener = new Object();
fileListener.change = function(eventObj:Object):Void {
trace("--------------------------");
//trace(eventObj.menuItem.attributes.label);
//
var menuNum = eventObj.menu._name;
trace(menuNum);
//
var menuItemNum = eventObj.menu.indexOf(eventObj.menuItem);
//trace(menuItemNum);
//
eventObj.menu.TextArea.setStyle("fontStyle", "italic");
//
var myItem:mx.controls.Menu =
xmlMenuBar.getMenuItemAt(eventObj.menuItem);
//trace(myItem);
//trace(eventObj.menu);
//trace("getMenuAt -> "+xmlMenuBar.getMenuAt(menuItemNum));
var instName = eventObj.menuItem.attributes.instanceName;
trace(eventObj.menuItem.menuNum);
//
xmlMenuBar.setMenuItemSelected(menuNum.menuItemNum, true);
//
switch(eventObj.menuItem.attributes.linkType) {
case "web":
//getURL(eventObj.menuItem.attributes.linkTo, "_blank");
break;
case "email":
//getURL("mailto:"+eventObj.menuItem.attributes.linkTo <mailto:> ,
"_blank");
break;
case "keyframe":
//gotoAndPlay(eventObj.menuItem.attributes.linkTo);
break;
}
};
// register the listeners with the separate menus
xmlMenuBar.addEventListener("change", fileListener);
stop();
Kind Regards,
Gareth Hudson.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com