Flex中使用Alert提示用户选择 Use Alert in Flex

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

在日常应用中,经常需要弹出一个Alert,提示用户进行选择. 如删除文件时提示用户是否确定删除,然后根据用户选择进行下一步操作:

应用举例:

AS代码:

		import mx.controls.Text;
		import mx.events.CloseEvent;
		import mx.controls.Alert;
		private function popAlert():void{
			Alert.yesLabel = "是";
			Alert.noLabel = "否";
			
			Alert.show("请选择是或者否","选择对话框",Alert.YES|Alert.NO,
			this,clickselectHandler,null,1);
		}
		
		private function clickselectHandler(event:CloseEvent):void{
			if (event.detail==Alert.YES){
			displaySelect_txt.text="选择了是";}
			else{
			
			displaySelect_txt.text="选择了否";}
		}

在MXML中使用上面的代码:

	
	

效果:

image image

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…)

Newer Posts <-> Older Posts



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