Actionscript 3 限制用户在Textfield中超过100

Actionscript 3 限制用户在Textfield中超过100,actionscript-3,actionscript,Actionscript 3,Actionscript,如何限制用户在Actionscript 3的文本字段中超过100 你可以这样做 function _handleTextChanges(evt:Event):void{ var target:TextInput = evt.currentTarget as TextInput; if(!target) return; if(parseInt(target.text) > 100){ target.text = "100"; }

如何限制用户在Actionscript 3的文本字段中超过100

你可以这样做

function _handleTextChanges(evt:Event):void{

     var target:TextInput = evt.currentTarget as TextInput;
     if(!target) return;
     if(parseInt(target.text) > 100){
         target.text = "100";
     }
     if(parseInt(target.text) < 0){
         Alert.show("You can't enter a number smaller than 0");
         target.text = "0";
     }

}
函数\u handleTextChanges(evt:事件):无效{
变量目标:TextInput=evt.currentTarget作为TextInput;
如果(!target)返回;
if(parseInt(target.text)>100){
target.text=“100”;
}
if(parseInt(target.text)<0){
Alert.show(“您不能输入小于0的数字”);
target.text=“0”;
}
}

我认为OP的意思是文本长度限制。如果是这样,请使用。

如果文本字段中有“a”怎么办?例外?你可以使用try-and-catch。尝试{parseInt(target.text);}catch(E exception){target.text=”“;}您也可以使用它