Erik’s Brain

The reward of a thing well done...

TextField.onSetFocus and onKillFocus Weirdness

I had to make a quick form using ActionScript 2 today. I wanted to add a quick little feature where the default “filler” text would be wiped out when someone clicks on the text field to start editing. Also, if the user left the text field without typing anything, the “filler” text would come back.

Simple stuff. And the code goes like this:

1
2
3
4
5
6
7
8
9
10
11
var startTextFirstName:String = "First Name";

tfFirstName.onSetFocus = function (obj:Object)
{
  if (tfFirstName.text == startTextFirstName) tfFirstName.text = "";
}

tfFirstName.onKillFocus = function (obj:Object)
{
  if (tfFirstName.text == "") tfFirstName.text = startTextFirstName;
}

I did that for three text fields. But it only worked for one of them. Weird.

Turns out the fix was simple. I had the uncooperative text fields set as MULTILINE input text fields. Change them to SINGLE LINE fields and all was well.

Comments