Listening for a click on the MX MenuBar control in Flex

来源:互联网 发布:4y4淘宝店铺装修网站 编辑:程序博客网 时间:2024/06/04 18:34
<?xml version="1.0" encoding="utf-8"?><!-- http://blog.flexexamples.com/2010/02/19/listening-for-a-click-on-the-mx-menubar-control-in-flex/ --><s:Application name="MenuBar_menuBarItems_addEventListener_test"        xmlns:fx="http://ns.adobe.com/mxml/2009"        xmlns:s="library://ns.adobe.com/flex/spark"        xmlns:mx="library://ns.adobe.com/flex/mx">     <fx:Script>        <![CDATA[            import mx.controls.Alert;            import mx.controls.menuClasses.MenuBarItem;             protected function init():void {                var mbi:MenuBarItem = mBar.menuBarItems[2] as MenuBarItem;                mbi.addEventListener(MouseEvent.CLICK, mbi2_click);            }             protected function mbi2_click(evt:MouseEvent):void {                Alert.show("You clicked the third menu bar item.");            }        ]]>    </fx:Script>     <mx:MenuBar id="mBar"            labelField="@label"            horizontalCenter="0" top="20"            creationComplete="init();">        <mx:dataProvider>            <s:XMLListCollection>                <fx:XMLList xmlns="">                    <menu label="File...">                        <item label="New" />                        <item label="Open" />                        <item label="Save" />                        <item label="Save As" />                        <fake type="separator" />                        <item label="Exit" />                    </menu>                    <menu label="Edit...">                        <item label="Cut" />                        <item label="Copy" />                        <item label="Paste" />                        <fake type="separator" />                        <item label="Undo" />                        <item label="Redo" />                        <fake type="separator" />                        <item label="radio button" type="radio" toggled="true" />                        <item label="check box" type="check" toggled="true" />                    </menu>                    <menu label="Help" />                </fx:XMLList>            </s:XMLListCollection>        </mx:dataProvider>    </mx:MenuBar> </s:Application>
原创粉丝点击