I have an input text field, where the user inputs a number, the user clicks on a "validate" button and i check his answer, if it equals "2" the answer is right, else the answer is wrong.
I used two icones, the "greenSign" for the right answer, and the "redSign" for the wrong one, those two icones are initially invisible, if the user inputs a number, one of these signs show up according to his answer.
Screen img: https://image.ibb.co/b9Ems6/aze.png.
the code:
greenSign.visible=false;
redSign.visible=false;
txt1.type = TextFieldType.INPUT;
validationButton.addEventListener(MouseEvent.CLICK, textInputCapture);
function textInputCapture(e:MouseEvent){
if(txt1.text=="2")
{redSign.visible=false; greenSign.visible=true;}
else
{redSign.visible=true; greenSign.visible=false;}
}
I want to verify what the user entered in the input text field without using the "validate" button. if the user inputs "2", the "greenSign" shows up automatically, and so on. any idea?
TextFields also dispatch Events, just like your Button. Look at this list.
I suggest the KeyUp Event, which will fire every time on the Up-Phase when somebody presses a Key on their Keyboard.
txt1.addEventListener(KeyboardEvent.KEY_UP, textInputCapture);
function textInputCapture(e:KeyboardEvent):void{...