Got it working, Tracy.  Thanks a lot.

On 4/1/08, Tracy Spratt <[EMAIL PROTECTED]> wrote:
>
>    In literal xml declarations, the braces do not create a binding.  They
> simply give access to the members of the parent scope.
>
>
>
> To do what you want, use an e4x expression to find the menuitem node you
> need, then set the attributes as desired.
>
>
>
> Tracy
>
>
>  ------------------------------
>
> *From:* [email protected] [mailto:[EMAIL PROTECTED] *On
> Behalf Of *nhid
> *Sent:* Tuesday, April 01, 2008 2:00 PM
> *To:* [email protected]
> *Subject:* [flexcoders] Disable/enable menuBar menuItem
>
>
>
> Hello,
>
>
>
> My menubar is like the following:
>
>
>
> ----------------------------
>
> In mxml file, *myFile.mxml*, I have:
>
> <mx:Application 
> xmlns:mx=http://www.adobe.com/2006/mxmlcreationComplete="initCollections();" >
>
> <mx:Script>
>
> <![CDATA[
>
> import mx.collections.*;
>
> [Bindable] public var menuBarCollection:XMLListCollection;
>
> [Bindable] public var model:MyModelLocator = MyModelLocator.getInstance();
>
> private var menubarXML:XMLList =
>
> <>
>
> <menuitem label="Menu1">
>
> <menuitem label="MenuItem 1-A" data="1A"
> enabled={model.menuEnabledFlags[0]}/>
>
> <menuitem label="MenuItem 1-B" data="1B"
> enabled={model.menuEnabledFlags[1]}/>
>
> </menuitem>
>
> <menuitem label="Menu2">
>
> <menuitem label="MenuItem 2-A" data="2A"/>
>
> <menuitem type="separator" />
>
> <menuitem label="MenuItem 2-B" >
>
> <menuitem label="SubMenuItem 3-A" data="3A"/>
>
> <menuitem label="SubMenuItem 3-B" data="3B"/>
>
> </menuitem>
>
> </menuitem>
>
> </>;
>
> // Event handler for the MenuBar control's itemClick event.
>
> private function menuHandler(event:MenuEvent):void {
>
> Alert.show("Label: " + [EMAIL PROTECTED] + "\n" +
>
> "Data: " + [EMAIL PROTECTED], "Clicked menu item");
>
> }
>
> // Event handler to initialize the MenuBar control.
>
> private function initCollections():void {
>
> menuBarCollection = new XMLListCollection(menubarXML);
>
> }
>
> private function changeMenu():void {
>
> menuEnabledFlags[0] = true;
>
> menuEnabledFlags[1] = false;
>
> }
>
> ]]>
>
> </mx:Script>
>
> <mx:MenuBar labelField="@label" itemClick="menuHandler(event);"
> dataProvider="{menuBarCollection}" />
>
> <mx:Button label="Change Enabled/Disabled Menu" click="changeMenu()"/>
> </mx:Application>
>
> ---------------
>
> In *MyModelLocator.as* file, I have:
>
> public var menuEnabledFlags:Array = [false, true];
>
> --------------------
>
> Initially, when the application is loaded, "MenuItem 1-A" is disabled, and
> "MenuItem 1-B" is enabled as the flags are defined in MyModelLocator.as
>
> I want to dynamically change enable/disable flags for the item "MenuItem
> 1-A" and "MenuItem 1-B" in .as (Script) file. So I changed the value of
> menuEnabledFlags as such menuEnabledFlags[0] = true; menuEnabledFlags[1] =
> false;
>
> I expected "MenuItem 1-A" will be enabled and "MenuItem 1-B" will be
> disabled.
>
> However, the change didn't reflect on the menubar.
>
> How can I dynamically enable/disable "MenuItem 1-A" and "MenuItem 1-B"?
>
> Please advise
>
> Thanks!
>
> 
>

Reply via email to