Copy link to clipboard
Copied
Hey guys,
I'm working on a desktop app and I am trying to get my Focus_IN and Focus_OUT to work the way I want it. This is what I have so far:
var defaultText="Enter Names Here"
txtNames.text=defaultText
txtNames.addEventListener(FocusEvent.FOCUS_IN,function(){txtNames.text=''});
txtNames.addEventListener(FocusEvent.FOCUS_OUT,function(e:FocusEvent){
e.currentTarget.text=(e.currentTarget.text=='')?'Enter Names Here':e.currentTarget.text;});
It works fine. My only problem is that once someone enters data into txtNames I want that data to remain, even if clicked off and then clicked back in. Right now, if you put data in, click off (data stays) but when you click back in to . . . oh let's say modify what you previously entered, the entire data entry is removed on tf entry.
Any ideas?
Thanks!
You should not build your functions into the listener like you have done. Get them separate and refer to them by name only in the listeners.
The reason you lose what's in the textfield is having your event handler function assigning them to be empty...
function(){txtNames.text=''}
Maybe just get rid of the FOCUS_IN listener to begin with and then decide what you really want to have happen when focus is obtained.
Copy link to clipboard
Copied
You should not build your functions into the listener like you have done. Get them separate and refer to them by name only in the listeners.
The reason you lose what's in the textfield is having your event handler function assigning them to be empty...
function(){txtNames.text=''}
Maybe just get rid of the FOCUS_IN listener to begin with and then decide what you really want to have happen when focus is obtained.
Copy link to clipboard
Copied
Thanks Ned, that was it! I scrapped the FOCUS_IN and it works exactly the way I want it to! Awesome!
Copy link to clipboard
Copied
You're welcome