在Flex 4中以编程方式启用/禁用menuBar按钮 [英] Programatically enable/disable menuBar buttons in Flex 4

查看:113
本文介绍了在Flex 4中以编程方式启用/禁用menuBar按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Flex4(AIR)项目中具有以下XML,用于定义菜单界面的开始:

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>

我正在尝试找到一种语法,通过单击加载",可以在文件加载后将保存按钮设置为enabled = true,但是我无法弄清楚该语法,有人可以提出建议吗?

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.

当前检测按钮单击的方式是通过Switch/Case测试MenuEvent event.item.@ label的String结果.也许这不是最好的方法?

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?

推荐答案

回答我自己的问题....再次.我正在做的事情又是怎么回事,似乎没人想回答?

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

无论如何,这里是:

事实证明,由于菜单栏是用XML定义的,并且完全是任意的,所以它完全取决于您决定如何定义菜单,在我的情况下,根据上述菜单XML,更改可启用"状态的语法保存按钮的内容如下.

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";

其中enubarXML是一个XMLListCollection,其中包含我分别重新定义的XMLList.

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);
        }

当然还有菜单栏的XML定义(根据需要自定义):

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.

这篇关于在Flex 4中以编程方式启用/禁用menuBar按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆