[英]How to add event listeners to the numeric stepper's text box?
我有一个数字步进器,我想在其文本框中添加一个事件监听器:
use namespace mx_internal;
durationStepper.inputField.addEventListener(Event.CHANGE,durationStepperTextInputChanged);
private function durationStepperTextInputChanged(event:Event):void
{
use namespace mx_internal;
trace(durationStepper.inputField.text);
}
但是,事件功能不执行! 我在这里放了一个断点,但没有达到! 我在这里想念什么? 谢谢。
问题在于,开发人员已停止冒泡Change事件。 如果转到NumericStepper的源文件,则可以找到它。 这是两个函数,它们使您无法获取事件。
override protected function createChildren():void
{
super.createChildren();
if (!inputField)
{
inputField = new TextInput();
//some code
//some code
inputField.addEventListener(Event.CHANGE, inputField_changeHandler);
addChild(inputField);
}
}
private function inputField_changeHandler(event:Event):void
{
// Stop the event from bubbling up.
event.stopImmediatePropagation();
var inputValue:Number = Number(inputField.text);
if ((inputValue != value &&
(Math.abs(inputValue - value) >= 0.000001 || isNaN(inputValue))) ||
inputField.text == "")
{
_value = checkValidValue(inputValue);
}
}
如您所见,第二个函数具有event.stopImmediatePropagation();。
在这种情况下,您有两个选择:要么找到另一种实现逻辑的方法,要么可以复制组件的源代码并消除此代码行。
可以重写该函数,但这是私有的。
我试图选择第二种方式。 它完美地工作! 它不仅是* .as文件,而且还使用了其他文件。
您可以在此处下载组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.