Skip to main content
Inspiring
November 29, 2007
Question

AS2. TextField onSetFocus select all

  • November 29, 2007
  • 6 replies
  • 3238 views
Hi there,

Having some problems to determine that when a textfield is selected the full
content is selected.

tried:

TextField.onSetFocus = function ():Void {
Selection.setFocus (this);
Selection.setSelection (0, this.length);
}
TextField.onKillFocus = function ():Void {
Selection.setSelection ();
}

No result. Any help...

Thanks


This topic has been closed for replies.

6 replies

kglad
Community Expert
Community Expert
December 2, 2007
use your textfield's instance name, not the variable associated with your textfield.
Inspiring
December 2, 2007

Exactly ;)

var tFieldScope:TextField = txt;

txt.mouseListener = new Object ();
txt.mouseListener.onMouseUp = function () {
_global.setTimeout (tFieldScope.selectAll, 1, tFieldScope);
}

txt.onSetFocus = function ():Void {
Mouse.addListener(this.mouseListener);
}

txt.onKillFocus = function ():Void {
Mouse.removeListener(this.mouseListener);
_global.setTimeout (tFieldScope.selectAll, 100, tFieldScope);
}



> actually, you should define a mouseUp in your onSetFocus and in your
> mouseUp handler setSelection and null the mouseUp. that would be perfect.


kglad
Community Expert
Community Expert
December 2, 2007
no setTimeout is needed. that's the point of waiting for a mouseUp event. and i'm not sure about your paths.

the following is probably easier to understand:

kglad
Community Expert
Community Expert
November 30, 2007
actually, you should define a mouseUp in your onSetFocus and in your mouseUp handler setSelection and null the mouseUp. that would be perfect.
kglad
Community Expert
Community Expert
November 30, 2007
you're welcome.
Inspiring
November 30, 2007

Thanks a lot Kglad ;)


kglad
Community Expert
Community Expert
November 29, 2007
use a delay (like setInterval) to setSelection because your mouseUp resets focus. also, this.length should be this.text.length (though you won't usually want to use "this" in your setInterval target function).