Selection.setFocus(textfield)

I don’t really know what I’m doing I’m completely gone in my own code, I think I’m going around in circles! :*(

Selection.setFocus(textfield);
if (Selection.getFocus() == textfield)) {
Key.addListener(textfield));
} else {
Selection.setFocus(textfield));
}

Ok let me explain what I want to do: when my movie loads I want “textfield” to be focused, so I use

Selection.setFocus(textfield);

Fine! But on a frame before this I have a button to enter my site! Now as soon as you click this button it changes the focus so that when I enter the frame with the textfield it is no longer focused! Make sense?:stuck_out_tongue: Well on this frame once the textfield is focused you can enter text right away! and then I have this listener which listens :stuck_out_tongue: to an event within the textfield! Ok now I’m even more confused then when I started explaining this! =) Anyway I want the textfield to be focused when you enter this frame and if the user focuses something else, well then they will have to focus the textfield themselves. Basicly I just want the the textfield to be focused on load, but the problem is my button at the start! What?:crazy:

Hehe well ermmmm yes, that made not alot of sense to me :crazy: . How about you post the fla so i can see what u mean
:slight_smile:

if you have Selection.setFocus(textfieldname) on the frame it appears, it should select that textfield right away unless the user clicks off. However, with the code you’re using, you have textField as the instance name which shouldnt be the case since that refers to the textField object. Name the field something else like inputField1 or something.

Also, as I said before, for Selection.getFocus() == textfield to work, you have to use eval on the getFocus since it returns a string of the textField and not the actual textfield itself.

eval(Selection.getFocus()) == inputField1

of course if you are setting the focus right there, theres no point in having that if condition because it will be run no matter what and set the listener. However, from what I understand, you want to add it everytime the user clicks on the textfield again? Since enter removes the listener right?

here look at this