[英]how to show Alert while the input text data is changing with actionscript 2?
i want to make an input text validation with FLASH ActionScript 2. The input text only displaying numbers above 5, so if i try to input number 0,1,2,3,4, the Alert will pop up and give an information that the data should be above 5. 我想使用FLASH ActionScript 2进行输入文本验证。输入文本仅显示大于5的数字,因此,如果我尝试输入数字0、1、2、3、4,则警报将弹出并提供以下信息:数据应高于5。
i want the validation processing while the input text is changing, because i dont use any button as the trigger. 我想在输入文本更改时进行验证处理,因为我不使用任何按钮作为触发器。
import mx.controls.Alert;
var tiListener:Object = new Object();
tiListener.change = function(evt_obj:Object)
{
if(inputText.text < 5)
{
trace("Numbers below 5 are not allowed");
Alert.show("Numbers below 5 are not allowed", "Error");
inputText.setFocus();
};
};
proj.addEventListener("change", tiListener);
Trace output is working well, but the Alert not shown. 跟踪输出运行良好,但未显示警报。 Any body have any solution?
任何身体有什么解决办法? Thanks..
谢谢..
The type of your inputText text is string
, and you want it to be number
. inputText文本的类型为
string
,并且您希望它为number
。 Use the parseInt
method to convert your string to an integer
: 使用
parseInt
方法将您的字符串转换为integer
:
inputText.onChanged = function(tf:TextField)
{
if (parseInt(tf.text) < 5)
{
trace("Numbers below 5 are not allowed");
Alert.show("Numbers below 5 are not allowed", "Error");
inputText.setFocus();
}
}
Place this code into your function, and that will be more clear: 将此代码放入您的函数中,这将更加清楚:
trace(typeof(tf.text));
trace(typeof(parseInt(tf.text)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.