Cor, first, bear in mind this is a gross hack, but I haven't found another
way around yet (if someone has found a more elegant way, please share!).
This is a solution (well, sort of) I came across when I had to deal with a
very similar problem.
In the IDE, the textfield actually gains focus, but the caret doesn't show
up; so, from a user perspective, it's like it doesn't have focus, I guess
(in fact, it could be counter intuitive for the user; you expect a caret to
signal that a text field has focus...)
Plus, in the browser, you don't gain focus immediately. You could register
to FOCUS_IN on the stage or even Event.ACTIVATE to detect when the swf gets
focus, but for some reason I just can't understand (a bug in the player or
maybe I'm missing something), it just doesn't seem to work.
Basically, your swf will gain focus when the user clicks on it. (I think it
will also gain focus if you "tab" to it, but I haven't covered that...)
So, when the user clicks down for the first time, you can reasonably assume
your swf has gain focus. So, what you could do is this:
In your constructor
stage.addEventListener(MouseEvent.MOUSE_DOWN,handleStageMouseDown);
And then
private function handleStageMouseDown(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_DOWN,handleStageMouseDown);
stage.focus = inputTextField;
}
Ugly and probably limited, but it has worked for me. Hope it works for you!
Cheers
Juan Pablo Califano
2009/3/1, Cor <[email protected]>:
>
> Thanks Juan!
>
> I am still not able to set the focus to the input textfield on opening.
> Any ideas?
>
> Kind regards
> Cor
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Juan Pablo
> Califano
> Sent: zondag 1 maart 2009 13:53
> To: Flash Coders List
> Subject: Re: [Flashcoders] InputTextField issue
>
> Hi,
>
> I'm almost certain that tabIndex is 1-based not 0-based, so it should be:
>
> txtName.tabIndex = 1;
> txtEmail.tabIndex = 2;
> txtAddress.tabIndex = 3;
> txtCity.tabIndex = 4;
>
> Also, Cor, when testing inside the IDE, you should check "disable keyboard
> shortchuts" in the control menu; otherwise, the IDE will trap the many of
> the key presses.
>
> Cheers
> Juan Pablo Califano
>
>
> 2009/2/28, Gerry <[email protected]>:
> >
> > You can look up focus (stage.focus = txtName; ), that will allow you to
> set
> > which textfield has focus and for tabbing use
> > tabIndex like this.
> >
> > txtName.tabIndex = 0;
> > txtEmail.tabIndex = 1;
> > txtAddress.tabIndex = 2;
> > txtCity.tabIndex = 3;
> >
> >
> > -Gerry
> >
> > On Feb 28, 2009, at 3:19 AM, Cor wrote:
> >
> > Hi Keith,
> >>
> >> I think I have put it wrong in my question.
> >> When running in the IDE is discards several, like: q,e,r,t, but the w
> is
> >> accepted.
> >> When I run in in html it accepts nothing.
> >>
> >> But in both cases when I first click the textfield the give it the focus
> >> it
> >> works as expected.
> >>
> >> So my problem really is: How to give the textfield the focus on start?
> >> And additional when I have a second textfield, how can I make is change
> >> from
> >> one to the other using the TAB key?
> >>
> >> Kind regards
> >> Cor
> >>
> >> _______________________________________________
> >> Flashcoders mailing list
> >> [email protected]
> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >>
> >
> > _______________________________________________
> > Flashcoders mailing list
> > [email protected]
> > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.237 / Virus Database: 270.11.4/1976 - Release Date: 02/28/09
> 17:21:00
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders