首先要設定目前年和月:
//月曆設定變量,目前月曆控件中的年和月
public var currentMonth:Number;
public var currentYear:Number;
.........................................
.........................................
this.currentYear=new Date().getFullYear();
this.currentMonth=new Date().getMonth()+1;
//因為月份從0開始計數,是以要加上1。
trace("****:\t"+currentMonth+"/"+currentYear+"******");
然後在DateChooser控件中申明
<mx:DateChooser id="dateChooser" x="139" y="83" borderColor="green"
scroll="changeMonth(event)" />
然後在changeMonth(event)事件中實作其事件,細節如下所示:
private function changeMonth(event:DateChooserEvent):void{
trace(event.detail);
// mx.controls.Alert.show("hello world!!!");
//擷取選中的月份
// mx.controls.Alert.show("目前的月份:\t"+dateChooser.selectedDate.getMonth().toString());
//有四種情況
//nextMonth && previousMonth
//nextYear && previousYear
var currentValue:String = new String(event.detail);
if(currentValue == "nextMonth"){
if(currentMonth >= 1 && currentMonth < 12)
this.currentMonth += 1;
else{
this.currentMonth = 1;
currentYear+=1;
}
}
else if(currentValue=="previousMonth"){
if(currentMonth > 1)
this.currentMonth -= 1;
else{
this.currentMonth = 12;
currentYear -= 1;
}
}
else if(currentValue == "nextYear"){
if(currentYear == 2100)
return;
currentYear += 1;
}
else if(currentValue=="previousYear"){
if(currentYear == 1900)
return;
currentYear -= 1;
}
//根據選中的年月來進行重新加載資料至DataGrid控件中
getAllCalenderService=new HTTPService();
getAllCalenderService.url="http://192.168.17.66:8080/Smarter/calendarSetting!getMonthSettings.action?year="+currentYear+"&month="+currentMonth;
getAllCalenderService.method="post";
getAllCalenderService.addEventListener(ResultEvent.RESULT,getAllCalenderFunc);
getAllCalenderService.send();
//重新向伺服器背景取資料
}
(完,待續...................................................................)
天道酬情,時不我待。
歲月不待人。。