Jun 25

很多时候我们都需要为星期一是第0天还是第1天而烦恼,接下来一点常用的小技巧演示了Flex中如何利用ActionScript封装类,对一周的日期名称进行封装(DateFormatter中),从而让我们无需关注是第0天还是第1天的问题。

让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
  3.  
  4.     <mx:Script>
  5.         <![CDATA[
  6.             private function doLabel(item:Date):String {
  7.                 return dateFormatter.format(item);
  8.             }
  9.         ]]>
  10.     </mx:Script>
  11.  
  12.     <mx:DateFormatter id="dateFormatter" formatString="MMM D, YYYY"/>
  13.  
  14.     <mx:DateField todayColor="red" labelFunction="doLabel" firstDayOfWeek="{Days.MONDAY}" />
  15.  
  16. </mx:Application>

下面是ActionScript封装类的代码:

  1. // ActionScript file
  2. package {
  3.     public class Days {
  4.         public static const SUNDAY:uint = 0;
  5.         public static const MONDAY:uint = 1;
  6.         public static const TUESDAY:uint = 2;
  7.         public static const WEDNESDAY:uint = 3;
  8.         public static const THURSDAY:uint = 4;
  9.         public static const FRIDAY:uint = 5;
  10.         public static const SATURDAY:uint = 6;
  11.     }
  12. }
代码:Peter deHaan 翻译/整理/编译:minidxer

written by Minidxer  |  tags: , , , ,

Related Post

Leave a Reply