加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex4 DateField自定义的日期选择控件,可选择时分秒

发布时间:2020-12-15 03:34:57 所属栏目:百科 来源:网络整理
导读:YJQDateField.mxml [html] ? view plain copy ? xml ? version = "1.0" ? encoding = "utf-8" ? ?? s:HGroup ? xmlns:fx = "http://ns.adobe.com/mxml/2009" ??? ???? xmlns:s = "library://ns.adobe.com/flex/spark" ??? ???? xmlns:mx = "library://ns.ado

YJQDateField.mxml

[html]? view plain copy
  1. <?xml?version="1.0"?encoding="utf-8"?>??
  2. <s:HGroup?xmlns:fx="http://ns.adobe.com/mxml/2009"???
  3. ????xmlns:s="library://ns.adobe.com/flex/spark"???
  4. ????xmlns:mx="library://ns.adobe.com/flex/mx"??
  5. ????horizontalAlign="left"??
  6. ????width="176"?height="22">??
  7. ?fx:Declarations>??
  8. ??<!--?将非可视元素(例如服务、值对象)放在此处?-->???
  9. </ ?fx:Script ??<![CDATA[?
  10. ???import?mx.controls.DateField;?
  11. ???import?mx.core.FlexGlobals;?
  12. ???import?mx.core.INavigatorContent;?
  13. ???import?mx.formatters.DateFormatter;?
  14. ???import?mx.managers.PopUpManager;?
  15. ????
  16. ???[Bindable]?
  17. ???/**?
  18. ????*?控件是否可以直接输入日期?
  19. ????*/?
  20. ???public?var?editable:Boolean;?
  21. ????*?日期格式??YYYY?MM?DD?HH?NN?SS?
  22. ???public?var?formatString:String?="YYYY-MM-DD?HH:NN:SS";?
  23. ???private?var?_date:Date?=?new?Date();?
  24. ????
  25. ???private?var?_year:int=0,_month:int=0,_day:int=0,_hour:int=0,_minute:int=0,_second:int=0;?
  26. ????*?设置显示日期字符串?
  27. ???public?function?set?text(value:String):void?
  28. ???{?
  29. ????_date=DateFormatter.parseDateString(value);?????
  30. ???}?
  31. ????*?设置日期?
  32. ???public?function?set?date(value:Date):void?
  33. ????_year?=?value.fullYear;?
  34. ????_month?=?value.month;?
  35. ????_day?=value.day;?
  36. ????_minute=value.minutes;?
  37. ????_hour=value.hours;?
  38. ????_second=value.seconds;??
  39. ????_date?=?value;??
  40. ????*?获取控件时间?
  41. ???public?function?get?date():Date?
  42. ????return?_date;?
  43. ????*?获取Chooser日期?
  44. ???public?function??onGetDate(y:int,mo:int,d:int,h:int,mi:int,s:int):void?
  45. ????this._year=y;?
  46. ????this._month?=?mo;?
  47. ????this._day?=?d;?
  48. ????this._hour?=?h;?
  49. ????this._minute?=?mi;?
  50. ????this._second?=?s;?
  51. ????_date?=?new?Date(_year,_month,_day,_hour,_minute,_second);?
  52. ????_inSelected?=?false;?
  53. ???}????
  54. ???private?var?_inSelected:Boolean?=?false;?
  55. ???/**?
  56. ????*?选择年月日?
  57. ????*/?
  58. ???protected?function?chooseDate_LBtn_clickHandler(event:MouseEvent):void?
  59. ???{?
  60. ????//?TODO?Auto-generated?method?stub?
  61. ????if(_inSelected?==?true)?
  62. ?????return?;?
  63. ????var?dateChooser:YJQChooseDate?=?new?YJQChooseDate();??????
  64. ????dateChooser.setDate(date.fullYear,date.month,date.date,date.hours,date.minutes,date.seconds);?????
  65. ????dateChooser.onReturnTime?=?onGetDate;?
  66. ????dateChooser.cancelHandler?=?function():void?
  67. ????{?
  68. ?????_inSelected?=?false;?
  69. ????}?
  70. ????dateChooser.x?=?event.stageX;?
  71. ????dateChooser.y?=?event.stageY;?
  72. ????PopUpManager.addPopUp(dateChooser,FlexGlobals.topLevelApplication?as?DisplayObject);?
  73. ????_inSelected?=?true;?
  74. ???}???
  75. ???private??function?DateToString(d:Date,format:String):String?
  76. ????//YYYY-MM-DD?HH:NN:SS?
  77. ????var?str:String?=?format;?
  78. ????str=str.replace("YYYY",d.fullYear);?
  79. ????str?=?str.replace("MM",d.month+1);?
  80. ????str=str.replace("DD",d.date);?
  81. ????str=str.replace("HH",d.hours);?
  82. ????str=str.replace("NN",d.minutes);?
  83. ????str=str.replace("SS",d.seconds);?
  84. ????return?str;?
  85. ???}?
  86. ???override?public?function?toString():String?
  87. ????return?DateToString(_date,formatString);?
  88. ??]]>??
  89. s:TextInput?id="date_input"??text="{DateToString(_date,formatString)}"??height="100%"?width="100%"?/>???
  90. mx:LinkButton?label=">>"?id="chooseDate_LBtn"?click="chooseDate_LBtn_clickHandler(event)"?/>??
  91. ???
  92. ???
  93. s:HGroup>??
YJQChooseDate.mxml

copy

    s:BorderContainer?xmlns:fx="http://ns.adobe.com/mxml/2009"???
  1. ????xmlns:mx="library://ns.adobe.com/flex/mx"??????
  2. ????minWidth="200"?maxWidth="200"??
  3. ????minHeight="260"?maxHeight="260"????????
  4. ????width="200"?height="260" ??<!--?将非可视元素(例如服务、值对象)放在此处?-->??
  5. ??<![CDATA[?
  6. ???import?mx.events.FlexEvent;?
  7. ????*?year?month?day??hour??minute?second?
  8. ???public?var?onReturnTime:Function;?
  9. ???private?var?_hour:int?=?0;?
  10. ???[Bindable]?
  11. ???private?var?_minute:int?=0;?
  12. ???private?var?_second:int?=0;?
  13. ???private?var?_year:int,_month:int,_day:int;?
  14. ???public?function?setDate(year:int,month:int,day:int?,hour:int,minute:int,second:int):void?
  15. ????_year=year;?
  16. ????_month=month;?
  17. ????_day=day;?
  18. ????_hour?=?hour;?
  19. ????_minute=minute;?
  20. ????_second=second;?
  21. ????*?输入小时是否合理?
  22. ???protected?function?hour_focusOutHandler(event:FocusEvent):void?
  23. ????if(isNaN(Number(hour.text)))?
  24. ????{?
  25. ?????hour.text=_hour.toString();?
  26. ?????return;?
  27. ????_hour?=?int(hour.text);?
  28. ????if(_hour<0)?
  29. ?????_hour=0;?
  30. ????else?if(_hour>23)?
  31. ?????_hour=23;?
  32. ????hour.text?=?_hour.toString();?????
  33. ????*?输入分钟是否合理?
  34. ???protected?function?minute_focusOutHandler(event:FocusEvent):void?
  35. ????if(isNaN(Number(minute.text)))?
  36. ?????minute.text=_minute.toString();?
  37. ?????return;?
  38. ????}?
  39. ????_minute?=?int(minute.text);?
  40. ????if(_minute<0)?
  41. ?????_minute=0;?
  42. ????else?if(_minute>59)?
  43. ?????_minute=59;?
  44. ????minute.text?=?_minute.toString();??
  45. ????*?输入秒是否合理?
  46. ???protected?function?second_focusOutHandler(event:FocusEvent):void?
  47. ????if(isNaN(Number(second.text)))?
  48. ?????second.text=_second.toString();?
  49. ????_second?=?int(second.text);?
  50. ????if(_second<0)?
  51. ?????_second=0;?
  52. ????else?if(_second>59)?
  53. ?????_second=59;?
  54. ????second.text?=?_second.toString();??
  55. ????*?双击代表选择?
  56. ???protected?function?vgroup1_doubleClickHandler(event:MouseEvent):void?
  57. ????ok_clickHandler(null);?
  58. ????*?返回日期?
  59. ???protected?function?ok_clickHandler(event:MouseEvent):void?
  60. ????//?TODO?Auto-generated?method?stub?
  61. ????var?date:Date?=?dateChosser.selectedDate;?????
  62. ????onReturnTime(date.fullYear,date.day,147); background-color:inherit">????try?
  63. ?????PopUpManager.removePopUp(this);?
  64. ????catch(error:Error)?
  65. ?????this.parent.removeChild(this);?
  66. ???public?var?cancelHandler:Function;?
  67. ????*?取消日期选择?
  68. ???protected?function?cancel_clickHandler(event:MouseEvent):void?
  69. ????cancelHandler();?
  70. ?
  71. ????*?DateChooser加载完成后执行?
  72. ???protected?function?dateChosser_creationCompleteHandler(event:FlexEvent):void?
  73. ????dateChosser.selectedDate?.setFullYear(_year,_day);?????
  74. s:VGroup?width="100%"?height="100%"? ??mx:DateChooser?width="100%"?id="dateChosser"??? ?????
  75. mx:DateChooser ??s:HGroup?paddingTop="0"?paddingLeft="10"?width="100%"?horizontalAlign="left" ???s:TextInput?id="hour"??width="23"?text="{this._hour.toString()}"??focusOut="hour_focusOutHandler(event)"? ???s:Label?paddingTop="4"?text="时:"???/>??
  76. ?????
  77. s:TextInput?id="minute"??width="21"?text="{this._minute.toString()}"??focusOut="minute_focusOutHandler(event)"s:Label?paddingTop="4"?text="分:"????s:TextInput?id="second"??width="22"?text="{this._second.toString()}"??focusOut="second_focusOutHandler(event)"s:Label?paddingTop="4"?text="秒:"?s:HGroup?width="100%"?horizontalCenter="true"?s:Button?label="确定"?id="ok"?click="ok_clickHandler(event)"?mx:Spacer?width="100%"?s:Button?label="取消"?id="cancel"?click="cancel_clickHandler(event)"?s:VGroups:BorderContainer>??
测试文件
copy
    s:Application?xmlns:fx="http://ns.adobe.com/mxml/2009"???
  1. ??????xmlns:s="library://ns.adobe.com/flex/spark"???
  2. ??????xmlns:mx="library://ns.adobe.com/flex/mx"???
  3. ??????creationComplete="application1_creationCompleteHandler(event)"??
  4. ??????xmlns:supportClasses="com.esri.ags.skins.supportClasses.*"???
  5. ??????minWidth="955"?minHeight="600"?xmlns:YJQDateField="YJQDateField.*"s:layoutsupportClasses:AttachmentLayout???import?mx.controls.Alert;?
  6. ???import?mx.events.FlexEvent;?
  7. ???protected?function?application1_creationCompleteHandler(event:FlexEvent):void?
  8. ????var?date:Date?=?DateFormatter.parseDateString("2011-08-06?14:21:25");?
  9. ??]]>??
  10. <!--?将非可视元素(例如服务、值对象)放在此处?-->??
  11. YJQDateField:YJQDateField?s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读