August 29th, 2008 by Kyle
Tags: as3, calendar, calendar control, datechooser, Flex
Posted in: ActionScript, Flex
The datachooser control doesn’t expose a way to disable the individual year up/down arrows, only the entire year Navigation (via yearNavigationEnabled).
But in looking at the internals of the dataChooser.as class you can get at the Buttons in an unsupported way.
mx_internal var upYearButton:Button;
mx_internal var downYearButton:Button;
These are the mx_internal scoped buttons for the up/down year.
You could technically extend the datechooser class and then create methods to enable/disable these buttons (if they exist).
Then you could enable/disable them using logic based on what you are setting for selectable ranges.
This is what I have done in the following example
Download a zipfile containing the source to this sample.
Browse the source of this example.
Or continue into the blog entry to see the source:
Here is the app code:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*" creationComplete="disabledate();">
<mx:Script>
<![CDATA[
import mx.events.DateChooserEvent;
public function checkDateSelectionEvent(event:Event):void{
var now:Date = new Date();
var nowYr:int=now.fullYear;
var displayedYr:int = DateField.displayedYear;
if(displayedYr > nowYr){
DateField.enableDownYrButton(true);
}
else{
DateField.enableDownYrButton(false);
}
}
private function disabledate():void {
var now:Date = new Date();
var today:Date = new Date(now.getFullYear(),
now.getMonth(),
now.getDate());
// Departure date can be today or later.
DateField.selectableRange = { rangeStart: today };
DateField.enableDownYrButton(false);
}
]]>
</mx:Script>
<mx:HBox>
<MyDateChooser id="DateField" click="checkDateSelectionEvent(event)"
enabled="true" showToday="true" color="#0A0A09" todayColor="#93F5E8"
visible="true" width="225" yearNavigationEnabled="true" >
</MyDateChooser>
</mx:HBox>
</mx:Application>
Here is the code for the custom component:
<mx:DateChooser xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.core.mx_internal;
use namespace mx_internal;
public function enableUpYrButton(b:Boolean):void{
super.mx_internal::upYearButton.enabled=b;
}
public function enableDownYrButton(b:Boolean):void{
super.mx_internal::downYearButton.enabled=b;
}
]]>
</mx:Script>
</mx:DateChooser>
Tweet
1 Comment »

September 3rd, 2009 at 11:53 am
Excellent site, keep up the good work