Programatically Enable or Disable Menu Items in Flex 3

Attach is the code snippet I'm using.  I've tried everything to programmatically disable / enable a menu item like "Down" but nothing works for me.

Any ideas would be much appreciated.  
<mx:XML format="e4x" id="myMenuData">
        <root>
            <menuitem id="menuDrill" label="Drill =>" >
                <menuitem id="menuDown" label="Down" toggled="false" enabled="true"/>
                <menuitem id="menuUp" label="Up" toggled="false" enabled="true"/>
            </menuitem>
            <menuitem type="separator"/>
            <menuitem label="Lock / Unlock" type="check" toggled="false"/>
            <menuitem type="separator"/>   
            <menuitem label="Reset Graph" toggled="false"/>  
        </root>
    </mx:XML>
 
============Action Script Code===================
var pt:Point = new Point(event.localX, event.localY);
			
                myMenu = Menu.createMenu(null, myMenuData, false);
 
                pt = event.target.localToGlobal(pt);
                myMenu.labelField="@label";
 
                myMenu.show(pt.x, pt.y);

Open in new window

bc24flAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ralf KlattEmployee in Civil ServiceCommented:
Hi,

you might like to try the sample at http://livedocs.adobe.com/flex/3/langref/mx/controls/Menu.html

If that sample also doesn't work, we should have a look at you environment.


Best regards,
Raisor
0
bc24flAuthor Commented:
There isn't an example of what I'm looking for there.

If you look through the menu items on your browser you will notice some menu items grayed out and unclickable.  This is what I want to do but in flex using actionscript 3.0.  

Thanks.
0
Ralf KlattEmployee in Civil ServiceCommented:
Hi,

I thought that the example at the end of the proposed page (scrolling all page down there) could serve you ... sorry!


Best regards,
Raisor
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

bc24flAuthor Commented:
Thanks for the help anyway.  I'll google something up and if I find the solution post it here.
0
Ralf KlattEmployee in Civil ServiceCommented:
Hi,

I'd be glad to see the solution that you're up to post ... it might give me an impression of what you were really looking for!


Best regards,
Raisor
0
DanRollinsCommented:
Have you tried
 <menuitem label="MenuItem A" enabled="False">
0
bc24flAuthor Commented:
What I'm really looking for is what DanRollins posted but instead of doing this:
 <menuitem label="MenuItem A" enabled="False">
I want to do the same in ActionScript or Programmatically as I mention in my post.  Something like

myMenu.myMenuItems.setEnable("DownMenuItem",false);

I hope this is clear enough.

Thanks.
0
bc24flAuthor Commented:
Wow this is my first question here on EE and no solutions to what I believe is pretty straight forward request from any programming language.  Does EE have paid consultants?  

Admin, when I posted this I didn't include "actionscript" group in the zones.  Is there a way to add this?
0
bc24flAuthor Commented:
We signed up for flex developer support through Adobe.  Flex 3.0 is relatively new and probably why we couldn't get a solution to our problem.  When our annual support plan expires I'll give experts-eschange another shot.  Thanks to all who responded.

Thanks.
0
DanRollinsCommented:
Have you looked at the
    MenuBar control
    http://livedocs.adobe.com/flex/3/html/help.html?content=Menus_9.html

It appears that "enabled" is an available attribute:
     http://livedocs.adobe.com/flex/3/html/help.html?content=menucontrols_3.html#410755

Perhaps you need to set
   enabled="true"
when you define the menuitem, so you can toggle it to "false" later.

=-=-=-=-=-=-=-=-=
As a PageEditor for another section, I could add "Macromedia Flash" to your list of sections, but I'd need to remove one of the existing ones (max 3).  Do you want me to remove this Q from "Miscellaeous Programming" and add it to "Macromedia Flash" ?
0
Ralf KlattEmployee in Civil ServiceCommented:
Hi,

I'm definitly sorry not having been able to point you to the right direction with your question ... all that I found out is, that a guy named Dirk has built a blog and seems to be a genius at the requested topic ... you might like to contact him directly through the contact data of his blog: http://www.richinternet.de/blog/


Hope that this hint leads you to the desired result!
Best regards,
Raisor
0
AKCSupportCommented:
So did anybody figure out how to do this?  I too need to do what bc24fl wants to do.  I have a menubar component that I generate with XML. Several of my options rely on an Internet connections (it's in an AIR app). I have a function that listens for changes on a URLMonitor object.  So when there is no net connection I disable some things.  I need to disable options in my menu. I know I need to set enabled="false".  What I don't know is how to access it from my AS code.  So I want to do something like:

MyMenusIDName.SubMenuIdName.enabled = false;

Anybody??
0
AKCSupportCommented:
Ok, so I figured this out after several trial and errors.  First here is my setup:

In my main MXML file, I have the actual Flex MenuBar component with properties.  That line of code looks lke:
<mx:MenuBar x="0" y="0" id="cbMainMenu" labelField="@label" showRoot="false" width="100%" buttonMode="true" dataProvider="/assets/menu.xml" />


The dataProvider is an XML file that looks like:
________________________________________
<?xml version="1.0" encoding="UTF-8"?>

<mainmenu>
      <menuitem label="File">
            <submenuitem label="Quit" enabled="true" />
      </menuitem>
      
      <menuitem label="Help">
            <submenuitem label="Online Help" enabled="true" />
            <submenuitem label="Contact Support" enabled="true" />
      </menuitem>
</mainmenu>
________________________________________



In my project, anytime I detect a change in Internet status, I want to set the "Contact Support" option to disabled/enabled.

So to get access to that here is the dot syntax:

cbMainMenu.dataprovider.source[0].menuitem[1].submenuitem[1].@enabled = false;

To break that down it's:
+ cbMainMenu is my MenuBar component's ID  (change this to match yours)
+ dataProvider is the XML file I have pasted above
+ source[0] is a reference to the actual data in the dataProvider
+ now I just walk the XML tree, skipping the root node, with menuitem[1].submenuitem[1].  That gets the 2nd sub-menu item of the 2nd menu item (remember the count starts at zero)
+ Last is @enabled  which is the enabled attribute (@).  It could have just as easily been @label to change the text.

Hope this helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbulleitCommented:
Thanks for the effort but I can't get this to work in Flex/AS 3.0.
0
mbulleitCommented:

I believe at least one solution here is to set the enable property on menuitem in the source XML file to a bindable dynamic variable and control the value of that variable using actionscript.

e.g.
SCRIPT:

[bindable]
private var toggleSwitch:Boolean = false;
private function controlMenu(event:Event):void{
     if ( event.currentTarget.selectedItem != undefined ) {
          toggleSwitch = true;
     }else{
          toggleSwitch = false;
     }
}

MXML: (XML Node of menu data provider)

<menuitem id="menuDown" label="Down" toggled="false" enabled="{toggleSwitch}"/>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.