Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple equality check not working

Community Beginner ,
Jun 10, 2014 Jun 10, 2014

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?

TOPICS
ActionScript
219
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 10, 2014 Jun 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".)

Translate
Community Expert ,
Jun 10, 2014 Jun 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".)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 10, 2014 Jun 10, 2014

How do you trace the length?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 10, 2014 Jun 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";

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 10, 2014 Jun 10, 2014

Thanks so much for your informative and clear replies

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 10, 2014 Jun 10, 2014
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines