Flex中弹出菜单使用 Use PopUpButton In Flex

Categories: Flex; Tagged with: ; @ October 12th, 2008 11:48

弹出菜单方式与下拉列表框[ComboBox]非常相似, 但PopUpButton是对button的扩展,而下拉列表框则用于列举出数据.

创建PopUpButton:

            import mx.controls.*;
            import mx.events.*;

            private var myMenu:Menu;

            // Initialize the Menu control, and specify it as the pop up object
            // of the PopUpButton control. 
            private function initMenu():void {
                myMenu = new Menu();
                var dp:Object = [{label: "New Folder"}, {label: "Sent Items"}, {label: "Inbox"}];        
                myMenu.dataProvider = dp;
                myMenu.selectedIndex = 0;       
                myMenu.addEventListener("itemClick", itemClickHandler);
                popB.popUp = myMenu;
                popB.label = "Put in: " + myMenu.dataProvider[myMenu.selectedIndex].label;
            }

            // Define the event listener for the Menu control's itemClick event. 
            private function itemClickHandler(event:MenuEvent):void {
                var label:String = event.item.label;        
                popTypeB.text=String("Moved to " + label);
                popB.label = "Put in: " + label;
                popB.close();
                myMenu.selectedIndex = event.index;
            }

在MXML中使用弹出菜单:

    

        
        
        
        
        
        
        

效果:
image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.