user3010564 user3010564 - 7 months ago 81
ActionScript Question

Automatically detect the value of an input text field in AS3

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:

the code:


txt1.type = TextFieldType.INPUT;

validationButton.addEventListener(MouseEvent.CLICK, textInputCapture);
function textInputCapture(e:MouseEvent){
{redSign.visible=false; greenSign.visible=true;}
{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?

Answer Source

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{...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download