views:

16

answers:

1

I have the following XML in my Flex4 (AIR) project that defines the start of my menu interface:

<mx:MenuBar x="0" y="0" width="100%" id="myMenuBar" labelField="@label" itemClick="menuChange(event)">
    <mx:dataProvider>
    <s:XMLListCollection>
    <fx:XMLList xmlns="">
        <menu label="File">
            <item label="New"/>
            <item label="Load"/>
            <item label="Save" enabled="false"/>
        </menu>
        <menu label="Help">
            <item label="About"/>
        </menu>
    </fx:XMLList>
    </s:XMLListCollection>
    </mx:dataProvider>
</mx:MenuBar>

I am trying to find the syntax that will let me set the save button to enabled=true after a file has been loaded by clicking "Load", however I can't figure out the syntax, can someone make a suggestion please.

Currently the way that button clicks are detected is by a Switch/Case testing the String result of the MenuEvent event.item.@label. Maybe this isn't the best way?

A: 

Answering my own question .... yet again. What is it with the stuff I'm doing nobody seems to want to answer???

Anyway, here it is:

It turns out that since the menubar is defined in XML and it's completely arbitrary, it depends totally on how you decide to define your menu, in my case, according to the menu XML above, the syntax to changethe "eanabled" state of the Save button would be as follows.

menubarXML.item.(@label=="Save").@enabled = "true";

where enubarXML is an XMLListCollection holding the XMLList which I redefined seperately.

[Bindable]
        public var menuBarCollection:XMLListCollection;

        private var menubarXML:XMLList =<>
            <menu label="File">
                <menuitem label="New" data="1A"/>
                <menuitem label="Open" data="1B"/>
                <menuitem label="Save" data="1C" enabled="false"/>
            </menu>
            <menu label="Help" data="2A">
                <menuitem label="About" data="2A"/>
            </menu>
            </>;

Then call this function on the apps creation complete:

private function initCollections():void {
            menuBarCollection = new XMLListCollection(menubarXML);
        }

and of course the XML definition of the menubar (customise this as required):

<mx:MenuBar id="myMenuBar" labelField="@label" itemClick="menuChange(event)" dataProvider="{menuBarCollection}"/>

Hope someone finds the fruits of my labour useful.

Hamid