I totally understand you're thinking but I don't think there's a built in
way of doing this. When you fire off the Alert component it has no knowledge
of where it was fired off from. I guess you could look into Extending Alert
to create your own MyAlert Class and override the show function (if
possible) to allow another parameter to be passed in so MyAlert.show can
receive an IUIComponent that is to get focus.

I've not looked into it but conceptually it should work but at some point
you'd still need to set the focus, either in the alertHandler or perhaps
inside the new MyAlert Class?

Personally, I would create a global variable to store the temp reference to
the object you want to refocus in the alertHandler().


Nick



2009/12/22 sasuke <uzumaki.naruto...@gmail.com>

>
>
>
>
> Nick Middleweek wrote:
> >
> > Hi,
> >
> > Check out the example on the Alert language reference...
> >
> http://livedocs.adobe.com/flex/3/langref/mx/controls/Alert.html#includeExamplesSummary
> >
> > You can assign a callback Handler like in the example:
> >
> > alertClickHandler()
> >
> > ... where you can check the button clicked and in that function you can
> > restore focus to the object you previously set focus to.
> Hi,
>
> Thanks for the response. I'm very well aware of the close handler but
> AFAICT, the close handler is given a CloseEvent object. If I want to set
> focus to my rogue element, I'd have to save the reference to my element in
> some global variable, which would then be used by my close handler to again
> set the focus. Isn't there is way in which I can make the close event set
> the focus or move the focus to the element which had the focus before the
> OK
> button was clicked? For e.g. I've something like:
>
> private function validate():Boolean
> {
> if(txtName.text == null || txtName.text == "")
> {
> controlToFocus = txtName;
> Alert.show("Please enter name", "", 0x4, this, alertClickHandler);
> return false;
> }
> return true;
> }
>
> private function alertClickHandler(event:Event=null):void
> {
> // Can this be replaced to *not* use a global state
> controlToFocus.setFocus();
> }
>
> I hope I've managed to express my concern here, suggestions appreciated.
> TIA.
>

Reply via email to