Search code examples
flashapache-flexactionscriptalertsetfocus

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...


Solution

  • 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.