Skip to main content
Inspiring
April 19, 2013
Answered

How to preserve special characters in dynamic textfield for text comparison?

  • April 19, 2013
  • 1 reply
  • 685 views

The problem is as follows:

Since I mostly develop for multiple languages I am forced to have dynamic textfields in my buttons which contain three lines (to account for the differnt text.lengths in different languages).

I then populate the textfields with strings out of an array or xml and use the textfields contents later in my button class to execute different code depending on the textfields content.

This works fine as long as I don`t use any special characters, like for example "\n".

var labels:Array = ["\nLABEL1","LABEL\n\n2"];

...

switch (e.currentTarget.txt.text)

            {

                case labels[0]:

                    doSomething();

                    break;

                case labels[1]:

                    doSomethingElse();

                    break;

           }

...

shows the right thing in the button label (breaks the text were I want it)

but stops to work

(with htmlText &  <br> its the same)

my workaround for the moment is to use filler spaces,

var labels:Array = ["                   LABEL1","LABEL                                                                        2"];

but that`s obviously ugly to setUp and requires a lot of trial/error to get it right for all languages.

Any ideas how to bypass that?

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

This is not a good idea to rely on button labels for linking to functionality to begin with - one shouldn't mix presentation and business logic. There are more than one dependencies. A better approach would be to decouple presentation from logic.

1 reply

Andrei1-bKoviICorrect answer
Inspiring
April 19, 2013

This is not a good idea to rely on button labels for linking to functionality to begin with - one shouldn't mix presentation and business logic. There are more than one dependencies. A better approach would be to decouple presentation from logic.

Inspiring
April 19, 2013

Bad habits die hard ;-)

Weird enough spelling the problem out and getting this response from you cleared my head and  I finally got an easy solution.

I simply attach a dynamic property to the movieclip, copy the array contents into them and instead of using the text-property for comparison I compare the MovieClips fresh created spectext property.

Voila: Now I can be lazy without too much of a bad conscience.

Inspiring
April 19, 2013

Hehe.  Good :-)