Dinesh Kumar
Dinesh Kumar

Reputation: 1499

Focus In /out Problem - button is not focused

When I press the *OK button of the alert box I want the txtOther.textbox to be in focus. Here the txtbox is focused when the alert box is displayed and when I press the OK button of the text box the txtOther.textbox is not in focus.

MXML SCRIPT:

<mx:Canvas id ="parentCanvas1" label="General" >
<mx:VBox id="parentBox1">
<mx:Canvas id="cvsGeneral"> 
<mx:TextInput id="txtOther" focusOut="txtOther_Validate();"/>
</mx:Canvas>
</mx:VBox>                              
</mx:Canvas>

<mx:Canvas id="parentCanvas2" >
<mx:HBox id="parentBox2" >
<mx:Button label="Save" id="btnSave" click="txtOther_Validate();" />
</mx:HBox>
</mx:Canvas>

////////////Action script////////////////////
public function txtOther_Validate(): void {     
     // here lets assume that the result variable is stored as "FAILURE"     
    if(result == "FAILURE"){  
        Alert.show("Please enter a valid Format Mask.");        
         txtOther.setFocus(); //   
         } 
}

Here even when the alert box is displayed the focus of the txtother.textbox is also set. But after pressing the OK button of the alert the Focus of the TxtOther.text box is not set. So here I want to trigger the foccus event after pressing the OK button of the alert window and not before. How to do that...

Upvotes: 1

Views: 1049

Answers (2)

Dinesh Kumar
Dinesh Kumar

Reputation: 1499

Instad of normal alert i put the alert like this

Alert.show("Please enter a valid Format Mask.", "Validation Error", Alert.OK, this, alrt_close);

and then i handle the alert event by

private function alrt_close(evt:CloseEvent):void {
    txtOther.setFocus(); 

This worked well for me.

Upvotes: 0

Mark Lapasa
Mark Lapasa

Reputation: 1654

When you invoke Alert.show(), store the returning Alert instance in a variable. On that variable, set up an event listener that will listen to your custom event. The purpose of the handler for that event is to set the focus on txtOther

Here's some code snippets:

private var alert:Alert = Alert.show(blah);

alert.addEventListener(mx.events.FlexEvent.REMOVE, removeHandler, false, 0, true);

private function removeHandler(event:FlexEvent):void
{
    txtOther.setFocus();
}

Upvotes: 1

Related Questions