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

Flex中addEventListener失败原因总结

Categories: Flex; Tagged with: ; @ October 9th, 2008 2:01

我绝对是个粗心大意的人, 写代码90%的时间是浪费在低级错误上. 今天不幸又add错一把, 索性将犯错原因归纳如下:

1.弱智级别:*****  隔着锅台上炕:  没有dispatch就addEventListener

2.弱智级别:****   驴唇不对马嘴:  addEventListener中Event类型不符
3.弱智级别:***    驴唇不对马嘴:   Listener参数中Event类型不符[FleBuilder会在编译时报错]
4.弱智级别**      脑子让驴踢了:   在addEventListener之前就dispatch Event[不太容易发现]

自定义事件常见错误:

1. Type不使用Const的String

2. 构造函数中super(type…)中type填写错误.

[Flex]DataGrid使用ActionScript增加列 Use AS Add DataGrid Column

Categories: Flex; Tagged with: ; @ October 9th, 2008 1:49

(more…)

[Tips]Flex中取得SQLite的最后插入记录的ID SELECT last_insert_rowid()

Categories: Flex; Tagged with: ; @ October 5th, 2008 23:16

(more…)

Flex Singleton Pattern—-Flex中的单例模式

Categories: Flex; Tagged with: ; @ October 1st, 2008 0:49

(more…)

Newer Posts <-> Older Posts



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