Wow finally got this working THANK YOU
EVERYBODY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Besides the syntax problems that you guys helped me with there was
another with the formatted xml data.

Since the code exists in a component the xmlns data was being (by
flex) inserted in the root of the xml data.  So below:

Source:
<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>

Trace:  

<mx:XML format="e4x" id="myMenuData" xmlns="com.blah.blah.blah.*">
        <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>

This is why I was getting a null when referencing it.  The fix is to
put xmlns="" in the root and your examples worked.

Many Thanks!

Irving

--- In [email protected], "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> 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: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of bc24fl
> Sent: Tuesday, June 03, 2008 12:32 PM
> To: [email protected]
> 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 [email protected] <mailto:flexcoders%40yahoogroups.com>
> , "valdhor" <stevedepp@> 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