0

这是一个功能示例:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            public function go():void{              
                Alert.show("The focus will return to txtOne. Look: ");
            }
        ]]>
    </mx:Script>
    <mx:VBox>
        <mx:TextInput id="txtOne" text="1" focusOut="go()"/>
        <mx:TextInput id="txtTwo" text="2"/>    
    </mx:VBox>  
</mx:Application>

当您从 txtOne 更改为 txtTwo 时,会显示警报,按 OK 后,焦点将返回到 txtOne。我不希望这种情况发生。如何解决这个问题?

4

2 回答 2

0

Alert.show有关闭回调参数,所以你会知道,它什么时候关闭并将焦点设置到其他东西。更新:您应该有标志,表明可以处理焦点事件:

private var needAlert:Boolean = true;

public function go():void
{
    if (needAlert)
    {
        Alert.show("The focus will return to txtOne. Look: ",
            "", 0, null, myCloseHandler);
        needAlert = false;
    }
}

private function myCloseHandler(event:CloseEvent):void
{
    this.setFocus();
    needAlert = true;
}
于 2011-10-26T13:14:15.310 回答
0

也试试这个以确保焦点也转到用户想要的地方

<mx:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.events.CloseEvent;
        import mx.managers.IFocusManagerComponent;
        private var ignoreFocusChange:Boolean = false;

        private var focusTargetOnReturn: IFocusManagerComponent;

        public function go():void
        {

            if(!ignoreFocusChange){
                focusTargetOnReturn = focusManager.getFocus();

                Alert.show("The focus will not return to txtOne anymore. Look: ",
                    "", 0, null, myCloseHandler);
            }
        }

        private function myCloseHandler(event:CloseEvent):void
        {               
            ignoreFocusChange = true;
            focusManager.setFocus(focusTargetOnReturn);
            ignoreFocusChange = false;
        }
    ]]>
</fx:Script>
<mx:VBox>
    <mx:TextInput id="txtOne" text="1" focusOut="go()"/>
    <mx:TextInput id="txtTwo" text="2"/>    
</mx:VBox>  

于 2013-04-29T23:50:16.343 回答