Yes, it can.

 

Valdhor's example works for me.  There is something going on with the
programmatic instantiation of the menu, it dissapears on click unless it
gets recreated in the handler.  That is just a bug and not necessary to
demonstrate the technique of disabling a menu item.

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of bc24fl
Sent: Tuesday, June 03, 2008 12:32 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Enable / Disable Flex Menu Items
Programmatically using AS 3.0

 

Ok I think I'm getting closer. In your example you create the menu
when the user clicks but in my code the menu has already been created
globally. Can the XML data be changed dynamically once the menu has
already been create?

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "valdhor" <[EMAIL PROTECTED]> wrote:
>
> OK, this is fairly buggy but it does show you can gray out a menu item
> from actionscript (Check the "Down" submenu item after clicking the
> "Lock / Unlock" menu item). I will leave the bug fixes and extras to
you
> :-)...
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
> layout="absolute"
> creationComplete="onComplete(event)">
> <mx:Script>
> <![CDATA[
> import mx.events.MenuEvent;
> import mx.events.FlexEvent;
> import mx.controls.Menu;
> import mx.controls.Alert;
> 
> public var myMenu:Menu = new Menu();
> 
> public function onComplete(event:FlexEvent):void
> {
> myMenu = Menu.createMenu(this, myMenuData, false);
> myMenu.labelField="@label";
> myMenu.show(100,100);
> myMenu.addEventListener(MenuEvent.ITEM_CLICK,
> menuClickHandler);
> }
> 
> private function menuClickHandler(event:MenuEvent):void
> {
> if(event.label == "Lock / Unlock")
> {
> 
> myMenuData..menuitem.(attribute("id")=="menuDown")[EMAIL PROTECTED] =
false;
> myMenu = Menu.createMenu(this, myMenuData, false);
> myMenu.labelField="@label";
> myMenu.show(100,100);
> }
> }
> ]]>
> </mx:Script>
> <mx:XML format="e4x" id="myMenuData">
> <root>
> <menuitem id="menuDrill" label="Drill =&gt;" >
> <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>
> </mx:Application>
>

 

Reply via email to