警报被多次触发 [英] Alert is triggered multiple times

查看:32
本文介绍了警报被多次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码的工作方式如下:

当我在 txtother.textbox 中输入不正确的值并聚焦时,将显示警告请输入有效的格式掩码.".在警报框中按下ok"按钮后,txtOther.focusout 甚至会再次触发.即在按下警报的 OK 后立即再次显示相同的 ALERT.

When I enter incorrect values in the txtother.textbox and focuses out, an alert will be displayed as "Please enter a valid Format Mask." . After pressing the "ok" button in the Alertbox the txtOther.focusout even is triggered again. i.e. immediately after pressing the OK of alert, the same ALERT is displayed again.

我已经添加了代码供您参考:

I have added the code for ur reference:

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

<mx:Canvas width="100%" height="5%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
<mx:HBox width="80%" height="100%" horizontalAlign="left">
<mx:Button width="64" label="Save" id="btnSave" click="btnSave_Click();" focusIn="txtOther_Validate();"/>
</mx:HBox>
</mx:Canvas>


//Validating action script is as follows:
public function txtOther_Validate():void{
    var formatMask: String = null;  
        if(txtOther.editable && txtOther.enabled){
            if(txtOther.text != ""){
                formatMask = txtOther.text;
                if(conditions to validate){
                    //some expression
                }               
                if(formatMask.length < 12){
                    Alert.show("Please enter format mask with minimum 12 digits.");
                    txtOther.setFocus();
                    return;
                }               VariableEditControl.getInstance().validateFormatMask(txtOther.text,validateFormatMask_Result,validateFormatMask_Fault, validateFormatMask_Error);
            }
        }   
}
public function validateFormatMask_Result(event:PLEvent): void {
    var result:String = event.getData().toString(); // here lets assume that the result variable is stored as "FAILURE"
    if(result == "FAILURE"){
        Alert.show("Please enter a valid Format Mask.");
        txtOther.setFocus(); //
    }
}

我不想警报一次又一次地出现..我需要这样一种方式,当按下警报的确定按钮时.txtother.text 应该是焦点,并且警报不应该像以前那样反复出现.

I don't want to the alert to come again and again .. I need it in such a way that when the ok button of alert is pressed. The txtother.text should be in focus, and the alert should not come again and again as before.

推荐答案

这是因为您再次将 focusIn="txtOther_Validate();" 放在确定"按钮上.只需删除 focusIn 处理程序就可以了.

it's because you have the focusIn="txtOther_Validate();" on the ok button a second time. just remove the focusIn handler and you should be fine.

这篇关于警报被多次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆