Skip to main content
Participant
December 14, 2007
Question

Search box problem - Capital letters

  • December 14, 2007
  • 2 replies
  • 268 views
Hi there,

I have a little search box, wich is used to go to somewhere else just when you type the word "albergaria".
But when you put "ALBERGARIA" or "Albergaria" with capital letters, the movie don't work.
This is my code:
stop();

var senderLoad:LoadVars = new LoadVars();

sender.onRelease = function() {
if ((pesquisa.text == "Albergaria")) {
gotoAndPlay("monica");
} else {
gotoAndPlay("monica2");
}
}

Can someone help me please? I'm just a poor begginer... :)
This topic has been closed for replies.

2 replies

Participant
December 17, 2007
It works, many thanks David.
Inspiring
December 14, 2007
orlando_ribas,

> if ((pesquisa.text == "Albergaria")) {

This condition of your if() statement is what does it. It compares the
contents of pesquisa.text to a literal string, "Albergaria" -- and that
string begins with a capital letter, with lowercase letters afterward.
Instead, it sounds like you want to check for the string "Albergaria"
without regard to case (doesn't matter where the capitals are), so you could
do something like this:

if ((pesquisa.text.toLowerCase() == "albergaria")) {

The reason that works is because the value of pesquisa.text is a string,
and the String class features a toLowerCase() method. In this context, it
doesn't matter what the user types. Might be albergaria, might be
Albergaria or aLbErGaRiA or any other combination. Doesn't matter. The
toLowerCase() method temporarily converts that value to lower case --
"albergaria" -- and compares that against the literal string "albergaria";
if they match, all is well; if they don't, your else is performed.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."