Apache flex Flex 4.12.0 setFocus触发单击事件
从4.6版迁移到Flex SDK 4.12.0的新版本时,我发现了一个bug或至少是一个不幸的特性。 传递“聚焦于组件”按钮时,将调度该按钮的单击事件 所需的应用程序状态:如果在tiTwo文本输入中具有实际焦点的用户按下Enter键,则焦点将传递到组件按钮上。 在文本输入上按Enter键后,不能在按钮上调度click事件Apache flex Flex 4.12.0 setFocus触发单击事件,apache-flex,focus,enter,textinput,flex-spark,Apache Flex,Focus,Enter,Textinput,Flex Spark,从4.6版迁移到Flex SDK 4.12.0的新版本时,我发现了一个bug或至少是一个不幸的特性。 传递“聚焦于组件”按钮时,将调度该按钮的单击事件 所需的应用程序状态:如果在tiTwo文本输入中具有实际焦点的用户按下Enter键,则焦点将传递到组件按钮上。 在文本输入上按Enter键后,不能在按钮上调度click事件 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe
<?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>
我想这是因为你用的是回车键,你试过用另一个键吗?我认为,如果你专注于一个按钮并按下enter键,点击事件就会被调度。当我在textinput中按下enter键后,我需要焦点移动/通过。如果我在按钮上并按enter键,单击事件将被调度,这是正常的。但在这种情况下,当我在textinput中按enter键时,单击事件会在按钮上调度。参见示例。请尝试运行上面的简单代码。如果取消注释//event.stopPropagation;它仍然不工作吗?这是可行的,但是在这个问题致命的大型应用程序中,停止传播可能会破坏很多工作。许多函数由FocusOut和Click事件处理。这是最后的解决办法,如果可能的话,我想避免。这个问题没有出现在第4.6节中,问题是为什么它会出现在第4.12.0节中。
4.6:
focusOut tiOne
focusOut tiTwo
4.12.0:
focusOut tiOne
focusOut tiTwo
button CLICKED