flex 只显示年、月的日期选择控件(TimeChooser)

摘要:
在网上找了好久,也没找到一个合意的日期控件,就对一篇博主的的一个显示年、月、日、时、分、秒的日期控件进行了改造,希望对那些和我有同样需求的童鞋有点帮助。好了直接贴代码:1˂?

需求:在客户端实现一个按月统计业务,需要用两个只能选择年和月的控件组合来选择起始月份,并将起始日期传入后台,返回统计数据。在网上找了好久,也没找到一个合意的日期控件,就对一篇博主的的一个显示年、月、日、时、分、秒的日期控件进行了改造,希望对那些和我有同样需求的童鞋有点帮助。

好了直接贴代码:

1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="165" height="25">
3     <mx:TextInput x="0" y="0" width="100" height="25" editable="{initeditable}" id="returnTime" text="{initvalue}"/>
4     <mx:Button x="102" y="2" icon="@Embed(source='mx/controls/DateChooser.png')" fontWeight="normal" width="22" click="open(event)" height="22"/>
5     <mx:Script>
6         <![CDATA[
7             importmx.containers.HBox;
8             importmx.containers.TitleWindow;
9             importmx.controls.Alert;
10             importmx.controls.Button;
11             importmx.controls.Label;
12             importmx.controls.NumericStepper;
13             importmx.controls.Text;
14             importmx.controls.TileList;
15             importmx.core.IFlexDisplayObject;
16             importmx.events.CloseEvent;
17             importmx.events.ListEvent;
18             importmx.events.NumericStepperEvent;
19             importmx.managers.PopUpManager;
20             
21             [Bindable]
22             private varinitvalue: String;
23             [Bindable]
24             private var initeditable:Boolean;
25             
26             public varresultTime:Text;
27             private var m_Number = 168;
28             
29             private var pop:Object;
30             private var isOpen:Boolean = false;
31             private var nowTime:Date = newDate();
32             
33             private function open(event:MouseEvent):void{
34                 resultTime = newText();
35                 if(!isOpen)
36 {
37                     pop = PopUpManager.createPopUp(this, TitleWindow, false); 
38                     pop.showCloseButton = true;
39 pop.addEventListener(CloseEvent.CLOSE,closeHandler);
40                     pop.move(event.stageX+event.target.width-event.localX+5,event.stageY-event.localY);
41                     //pop.title = nowTime.fullYear.toString() + " 年 " + (nowTime.month+1) + " 月";
42                     pop.title = "日期选择";
43                     pop.setStyle("fontSize",12);
44                     
45                     
46                     var yearChangeHandler:Function = function(evt:NumericStepperEvent):void{
47 nowTime.setFullYear(evt.value,nowTime.month,nowTime.date);
48 PopUpManager.removePopUp(pop as IFlexDisplayObject);
49                         isOpen = false;
50 open(event);
51 }
52                     
53                     var monthChangeHandler:Function = function(evt:NumericStepperEvent):void{
54                         nowTime.setFullYear(nowTime.fullYear,evt.value-1,nowTime.date);
55 PopUpManager.removePopUp(pop as IFlexDisplayObject);
56                         isOpen = false;
57 open(event);
58 }
59                     var testHandler:Function = function(event:ListEvent):void{
60                         resultTime.text = nowTime.fullYear + "-" + (nowTime.month+1);
61                         returnTime.text =resultTime.text;
62 }
63                     var onSubBtn_Click:Function = function(event:MouseEvent):void
64 {
65                         resultTime.text = nowTime.fullYear + "-" + (nowTime.month+1);
66                         returnTime.text =resultTime.text;
67                         
68 PopUpManager.removePopUp(pop as IFlexDisplayObject);
69                         isOpen = false;
70                     
71 }
72                     
73                     var hBoxTop:HBox = newHBox();
74                     hBoxTop.width =m_width;
75                     var year:NumericStepper = newNumericStepper();
76                     year.setStyle("fontSize",10);
77                     year.stepSize = 1;
78                     year.minimum = 1999;
79                     year.maximum = 2999;
80                     year.width = 60;
81                     year.height = 20;
82                     year.value =nowTime.fullYear;
83 year.addEventListener(NumericStepperEvent.CHANGE,yearChangeHandler);
84                     
85                     var y_label:Label = newLabel();
86                     y_label.text = "年";
87                     y_label.setStyle("textAlign","center");
88                     y_label.width = 15;
89                     
90                     var month:NumericStepper = newNumericStepper();
91                     month.setStyle("fontSize",10);
92                     month.stepSize = 1;
93                     month.minimum = 0;
94                     month.maximum = 13;
95                     month.width = 50;
96                     month.height = 20;
97                     month.value = nowTime.month+1;
98 month.addEventListener(NumericStepperEvent.CHANGE,monthChangeHandler);
99                     
100                     var m_label:Label = newLabel();
101                     m_label.text = "月";
102                     m_label.setStyle("textAlign","center");
103                     m_label.width = 15;
104                     
105 hBoxTop.addChild(year);
106 hBoxTop.addChild(y_label);
107 hBoxTop.addChild(month);
108 hBoxTop.addChild(m_label);
109                     
110                     
111 pop.addChild(hBoxTop);
112                     var subBtn:Button = newButton();
113 subBtn.addEventListener(MouseEvent.CLICK,onSubBtn_Click);
114                     subBtn.label = "确定";
115 pop.addChild(subBtn);
116                     isOpen = true;
117 }
118              else{
119 PopUpManager.removePopUp(pop as IFlexDisplayObject);
120                     isOpen = false;
121 }
122 }
123             
124             private function closeHandler(event:CloseEvent):void{
125 PopUpManager.removePopUp(event.target as IFlexDisplayObject);
126                 isOpen = false;
127 }
128             
129             public function set text(str:String):void{
130                 initvalue =str ;
131 }
132             public function gettext():String{
133                 returnreturnTime.text ;
134 }
135             
136             public function set editable(str:Boolean):void{
137                 initeditable =str;
138 }
139             public function get editable(): Boolean{
140                 returnreturnTime.editable;
141 }
142         ]]>
143     </mx:Script>
144 </mx:Module>

使用的时候将该模块添加到项目工程里,就可以方便使用了。

效果如下:

flex 只显示年、月的日期选择控件(TimeChooser)第1张

免责声明:文章转载自《flex 只显示年、月的日期选择控件(TimeChooser)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇samtools manu微信公众号分享时,提示invalid signature,签名错误下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

vs下调试程序时,把信息打印到输出窗口

重印:https://blog.csdn.net/cwj066/article/details/82423627 https://stackoverflow.com/questions/20508086/getting-rid-of-atltracegeneral-category-shown-in-atltrace-output方法1:编写一个变量参数函数...

sql 加减时间

另外,MySQL中还有两个函数subdate(),subtime(),建议,用date_sub()来替代。MySQLperiod_add(P,N):日期加/减去N月。mysql˃selectperiod_add,period_add|period_add|period_add|结果|200810|20080806|MySQLperiod_diff:日期P1-...

ROS学习之日志消息

ROS日志系统的核心思想是使程序生成一些短文本字符流,这些短文本字符是日志消息。ROS_…_ STREAM_ THROTTLE宏的每个实例在第一次执行时都会生成一条日志消息,随后的执行将被忽略,直到经过指定的时间间隔。...

PB各对象常用事件

1.触发窗口中事件名称的时间01.在激活窗口之前激活触发器02。单击触发器03.Close触发器04.CloseQuery在窗口被清除或关闭时触发。...

WindowsForm实现折叠菜单面板

在程序开发的过程中,有时候为了让我们程序的主要内容能够显示的区域更大,我们需要把一些面板折叠起来,今天就简单介绍一种菜单面板折叠的实现。首先,先用panel将构建出整体的页面布局,然后在菜单面板上添加上一个折叠按钮或者图片控件都可以,并将控件的Anchor属性成Top|Right,这样在页面折叠时,控件能够随着panel的宽度进行相对位置移动。private...

myEclipse

因此,更改windows–>preferences–>general–>editors–>fileassociations,将myeclipsejspedator设置为默认的myeclipse使用提示步骤5:更改代码提示快捷键。当前代码提示快捷键默认为ctrl+space,我们的输入方法也被切换,因此会出现冲突。...