Flex 4.12.0 setFocus触发click事件

时间:2014-05-20 07:48:55

标签: flex focus enter textinput flex-spark

在迁移到新版本的Flex SDK 4.12.0(从4.6版本)时,我发现了一个错误或至少是一个不幸的功能。 将焦点传递给组件按钮时,将调度按钮的单击事件。

必需的应用程序状态:如果用户(实际焦点在“tiTwo”文本输入中)按Enter键,则会在组件按钮上传递焦点。 按Enter键输入文本后,不能在“按钮”上调度单击事件。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="800" minHeight="600">  
<s:layout>
    <s:VerticalLayout gap="8" horizontalAlign="center" paddingTop="20"/>
</s:layout>
<fx:Script>
    <![CDATA[
        import mx.managers.IFocusManagerComponent;

        // BUTTON click handler
        protected function button_clickHandler(event:MouseEvent):void
        {
            status.text += "button CLICKED \n";
        }

        // TEXT INPUT focus out handler
        protected function ti_focusOutHandler(event:FocusEvent):void
        {
            status.text += "focusOut  " + event.currentTarget.id + "\n";
        }

        // TEXT INPUT key down handler (move focus to next focusable component)
        protected function ti_keyDownHandler(event:KeyboardEvent):void
        {
            // temp solution - not good for bigger application
            //event.stopPropagation();
            //event.stopImmediatePropagation();

            if(event.keyCode == Keyboard.ENTER) {
                var focusableComponent:IFocusManagerComponent = focusManager
                       .getNextFocusManagerComponent();
                focusManager.setFocus(focusableComponent);

                // same problem (enter click dispatch...)
                //focusManager.getNextFocusManagerComponent().setFocus();
            }
        }
    ]]>
</fx:Script>    
<s:Label id="introLabel" text="TAB vs ENTER test (Flex SDK 4.12.0)"
         color="0xDCDCDC" fontSize="18"/>

<!-- TI 1 -->
<s:TextInput id="tiOne" focusOut="ti_focusOutHandler(event)"
             keyDown="ti_keyDownHandler(event)" prompt="tiOne"/>
<!-- TI 2 -->
<s:TextInput id="tiTwo" focusOut="ti_focusOutHandler(event)"
             keyDown="ti_keyDownHandler(event)" prompt="tiTwo"/>    
<!-- BTN -->
<s:Button id="button" click="button_clickHandler(event)"
          label="BTN"/> 
<!-- TI 3 -->
<s:TextInput id="tiThree" focusOut="ti_focusOutHandler(event)"
             keyDown="ti_keyDownHandler(event)" prompt="tiThree"/>
<!-- TI 4 -->
<s:TextInput id="tiFour" focusOut="ti_focusOutHandler(event)"
             keyDown="ti_keyDownHandler(event)" prompt="tiFour"/>
<!-- TITLE -->
<s:Label id="title" text="Status:"
         color="0xDCDCDC" fontSize="14"/>
<!-- TEXT AREA -->
<s:TextArea id="status" height="400"
            editable="false" focusEnabled="false"/>
</s:Application>

如何修复此错误?这在Flash Player 11.6.602.168和Flash Player 13.0.0.182中发生(它是SDK问题),Apache SDK 4.11或4.12.1也出现同样的问题

可以跟踪4.6 vs 4.12.0(易于重现 - &gt; 启动示例应用,鼠标点击tiOne,按两次Enter键

4.6:
focusOut  tiOne
focusOut  tiTwo

4.12.0:
focusOut  tiOne
focusOut  tiTwo
button CLICKED 

0 个答案:

没有答案