Copy link to clipboard
Copied
I'm trying to use a MouseEvent.CLICK event to set focus to a TLFTextField and let the user type there:
var textField:TLFTextField = menuField.getTextField();
textField.stage.focus = textField;
textField.setSelection(0,0);
However, when this code executes the cursor appears in the TextField but the user can't type. What can I do to resolve this? A more detailed description follows:
I'm making an application which has several fields the user needs to fill out. The fields are dynamically generated and not always the same number, so I made a movieclip called MenuField and wrote a class for it to handle the functionality.
MenuField has two text regions, which are TLFTextFields inside container MovieClips. The first region, lblFieldName, is the label for the field (e.g. "Name:"). The second is the editable text region lblFieldValue The TLFTextFields are inside containers because I found if I tried to set lblFieldName's text from MenuField's constructor, it would reset immediately (TextFields are apparently not intitialized until the constructor of their parent has finished executing...)
The size and position of lblFieldValue is set dynamically based on the size of lblFieldName. The text in lblFieldValue starts out blank until the user enters something. Unfortunately, regardless of the width of the TextField, if the text is blank the user can only select the TextField by clicking on the very left edge of it, which is completely impractical. My solution was to add a mouse CLICK event to the entire MenuField, and try to set focus to the lblFieldValue TextField. But again, when the code above executes it places the cursor but doesn't allow the user to type. I'm sure I'm missing something simple. Any suggestions?
tlf textfields are problematic. unless you have a good reason to use them, you should use classic text.
Copy link to clipboard
Copied
what's menuField?
are you using one or more components?
Copy link to clipboard
Copied
Sorry I didn't explain that adequately. It's an instance of the MenuField MovieClip/class file I made. It has three child MovieClips, background (a simple graphic), lblFieldName (a MovieClip containing a TLFTextField) and lblFieldValue (a MovieClip containing a TLFTextField).
The code above is in another class refering to an instance of MenuField. I'm not sure if I should refer to textField.stage or just stage, but it seems to function the same either way.
I'm not using anything from the Flash component library.
Copy link to clipboard
Copied
tlf textfields are problematic. unless you have a good reason to use them, you should use classic text.
Copy link to clipboard
Copied
Yup, it really was that easy! Thanks!
Copy link to clipboard
Copied
you're welcome,
Find more inspiration, events, and resources on the new Adobe Community
Explore Now