• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

txtField Focus IN Focus OUT Issue

Community Beginner ,
Aug 30, 2012 Aug 30, 2012

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!

TOPICS
ActionScript

Views

619

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 30, 2012 Aug 30, 2012

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.

Votes

Translate

Translate
LEGEND ,
Aug 30, 2012 Aug 30, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 31, 2012 Aug 31, 2012

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines