4,328
社区成员
发帖
与我相关
我的任务
分享
package controls
{
import flash.events.Event;
import mx.controls.DateField;
import mx.events.FlexEvent;
public class CustomDateField extends DateField
{
private var _readonly:Boolean = false;
private var readonlyChanged:Boolean = false;
[Bindable("readonlyChanged")]
public function get readonly():Boolean
{
return _readonly;
}
public function set readonly(value:Boolean):void
{
_readonly = value;
readonlyChanged = true;
invalidateProperties();
dispatchEvent(new Event("readonlyChanged"));
}
override protected function commitProperties():void
{
super.commitProperties();
if (readonlyChanged && textInput)
{
textInput.editable = !_readonly;
readonlyChanged = false;
}
}
override protected function downArrowButton_buttonDownHandler(
event:FlexEvent):void
{
if (!_readonly)
super.downArrowButton_buttonDownHandler(event);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:co="controls.*" layout="vertical">
<co:CustomDateField id="dateField" selectedDate="{new Date()}"
editable="true" readonly="true" />
<mx:Button label="readonly" click="{dateField.readonly=!dateField.readonly}" />
</mx:Application>