how to show Alert while the input text data is changing with actionscript 2?

550 Views Asked by At

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.

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..

1

There are 1 best solutions below

2
helloflash On

The type of your inputText text is string, and you want it to be number. Use the parseInt method to convert your string to an 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)));