Hi everyone,
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 screenthis.createClassObject(mx.controls.MenuBar, 
"xmlMenuBar", 25);// XMLvar myDP_xml:XML;// Listener objectvar 
fileListener:Object;// 
====================================================================// Set up 
tab index etc.xmlMenuBar.tabEnabled = true;xmlMenuBar.tabIndex = 1;// 
====================================================================//define 
styles for the ComboBox componentxmlMenuBar.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; 
//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(instName); // 
xmlMenuBar.menuNum.setMenuItemSelected(instName, true);  // 
switch(eventObj.menuItem.attributes.linkType) {  case "web":   
//getURL(eventObj.menuItem.attributes.linkTo, "_blank");   break;  case 
"email":   //getURL("mailto:"+eventObj.menuItem.attributes.linkTo, "_blank");   
break;  case "keyframe":   //gotoAndPlay(eventObj.menuItem.attributes.linkTo);  
 break;   }};// register the listeners with the separate 
menusxmlMenuBar.addEventListener("change", 
fileListener);stop();////////////////////////////////////////////////////////////////////////////
And here's the xml test file used:
<?xml version="1.0" ?>  <menu>  <menuitem label="Organic 
Molecules">  <menuitem label="Google" instanceName="googleInstance" 
type="check" linkTo="http://www.google.com"; linkType="web" />  <menuitem 
type="separator" />   <menuitem label="BBC News" 
instanceName="bbcInstance" type="check" linkTo="[EMAIL PROTECTED] Subject" 
linkType="email" />   <menuitem label="Microsoft" 
instanceName="microsoftInstance" type="check" linkTo="testKeyframeLable" 
linkType="keyframe" />   </menuitem>  <menuitem label="Chemical 
Equilibrium">  <menuitem label="Undo" type="check" />   <menuitem 
type="separator" />   <menuitem label="Cut" type="check" />   
<menuitem label="Copy" type="check" />   <menuitem label="Paste" 
type="check" />   <menuitem label="Clear" type="check" />   
<menuitem type="separator" />   <menuitem label="Select All" 
type="check" />   </menuitem> </menu> <menuSettings 
menuHeight="20" menuWidth="220" xPos="250" yPos="0" menuFont="Verdana" 
menuFontSize="10" menuColour="0x66CCAD" />
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

Reply via email to