The code ended up being squashed into paragraphs, hopefully this paste will 
sort that out so that you can read it. Once again, my problem is that I have a 
problem with my MenuBar in the fact that I can't 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. // 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 { // var menuNum = eventObj.menu; // var 
menuItemNum = eventObj.menu.indexOf(eventObj.menuItem); // 
eventObj.menu.TextArea.setStyle("fontStyle", "italic"); // var 
myItem:mx.controls.Menu = xmlMenuBar.getMenuItemAt(eventObj.menuItem); var 
instName = eventObj.menuItem.attributes.instanceName; // 
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 menus 
xmlMenuBar.addEventListener("change", fileListener); stop(); > ----Original 
Message---- > From: [EMAIL PROTECTED] > Date: Jan 16, 2007 12:44:03 PM 
> To: [email protected] > Subj: [Flashcoders] MenuBar 
setMenuItemSelected problem. > > 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
_______________________________________________
[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