Skip to main content
Participating Frequently
June 10, 2014
Answered

Simple equality check not working

  • June 10, 2014
  • 5 replies
  • 269 views

Hi

one of my students has an error, and I can't see it.

He has a input text box (a), and he's looking to check that the user enters "one". If they get it right, it displays a message in dynamic text box (b)

var x:String = "one";

btn_done.onPress = function(){

  if (a.text != x){

  b.text="Wrong";

  trace(a.text);

  }

  else{

  b.text = "Right";

  }

}

No matter what one types, the response is "wrong". I've spent hours looking, but can't see the problem. Can anyone shed some light please?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer kglad

change the textfield from multiline to single line.

(when a text trace look like you expect but doesn't act the way you expect, trace its length, too.  that will reveal white space problems.  in your case you probably have a carriage return at the end of "one".  ie, "one\r".)

5 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 10, 2014

change the textfield from multiline to single line.

(when a text trace look like you expect but doesn't act the way you expect, trace its length, too.  that will reveal white space problems.  in your case you probably have a carriage return at the end of "one".  ie, "one\r".)

basil01Author
Participating Frequently
June 10, 2014

How do you trace the length?

kglad
Community Expert
Community Expert
June 10, 2014

strings have a length property:

var x:String = "one";

btn_done.onPress = function(){

  if (a.text != x){

  b.text="Wrong";

trace(a.text+" "+a.text.length);

  }

  else{

  b.text = "Right";

  }

}