VoodooBurger
VoodooBurger

Reputation: 233

How to clear a text-field on focus with AS3?

The theme question sais it all.

I have an input text-field on the stage that has some text describing text in it before the user types anything. Now, how do I clear this text when the user focuses on (clicks) the field?

Upvotes: 1

Views: 19003

Answers (4)

Erhan Demirci
Erhan Demirci

Reputation: 4209

important: userName is MovieClip and this movieClip's inside ı have TextField which name is txt.

userName.addEventListener(FocusEvent.FOCUS_IN, clearBox);
function clearBox(evt:FocusEvent):void
{
    userName.text="";
}

Upvotes: 1

Mercy
Mercy

Reputation: 1860

Try this Code

  txtMessage.addEventListener(FocusEvent.FOCUS_IN, clearBox);
  function textclearBox(FocusEvent)
   {
    txtUser.text="";//To Clear the Text Box
   }

Upvotes: 3

Moshe
Moshe

Reputation: 58067

This should do it. (Although, my AS3 is a bit rusty.)

textbox.addEventListener(FocusEvent.FOCUS_IN, clearBox);

function clearBox(e:FocusEvent){
  textbox.setText("");
}

Upvotes: 1

grapefrukt
grapefrukt

Reputation: 27045

Listen for the FocusEvent.FOCUS_IN event on your textfield and clear it once that fires. http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/events/FocusEvent.html

Upvotes: 4

Related Questions