Skip navigation
Currently Being Moderated

txtField Focus IN Focus OUT Issue

Aug 30, 2012 9:48 AM

Tags: #text #as3 #cs5.5 #actionscript #as3.0 #actionscript3 #focusing #focusout #focus_in

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!

 
Replies
  • Currently Being Moderated
    Aug 30, 2012 12:01 PM   in reply to Claunchster

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 31, 2012 5:37 AM   in reply to Claunchster

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points