Faris Zaini
Faris Zaini

Reputation: 3

how to check input text using ActionScript 3 with movie clip button?

im just working on my new project. All what i need is, i want to check input text using button, if the value on the input text box is equals 1, trace("true"), else trace ("false").

here's the example link http://localhostr.com/file/P2Q3bpn/test.fla

the problem is, when im trying to input text to 1, it's always goes to else, which means false. also all number. sorry for my bad english. here's what i did

var check:Boolean = false;
var input1:String;
var answer:String = "1";

MCButton.addEventListener(MouseEvent.CLICK, checkClick);

function checkClick(event:MouseEvent):void{
    input1= inputBox.text;
    check = true;
    if(input1 == answer){
        trace("true");
    }
    else trace("false");
}

thanks

Upvotes: 0

Views: 2283

Answers (2)

Ross Smith
Ross Smith

Reputation: 755

If your answers will always be numbers, try this:

 if(parseInt(input1) == parseInt(answer))
 { 
    ...
    ...
    ...
 }

Upvotes: 1

Valentin Simonov
Valentin Simonov

Reputation: 1768

Actually you got "multiline" turned on. So what you are getting is "1\n" where "\n" is "new line". Which is not equal to "1". Turn off multiline and it will be ok.

Upvotes: 1

Related Questions