将焦点设置在 Popup 的 textInput 控件上
我正在尝试创建一个带有可立即编辑的 TextInput 的弹出窗口。这意味着一旦显示弹出窗口,用户应该能够在 TextInput 中输入内容。
问题是我无法专注于文本输入。发生的情况是,当第一次按下某个键时,不会插入任何文本,只有在按下第二个键后,组件才会获得焦点,用户才能键入。例如,在弹出窗口打开后键入“test”会导致显示“est”...
出于某种原因,该组件仅在用户明确单击它或键入某些内容时才会获得焦点。以编程方式设置焦点不起作用。
有什么想法/建议吗?
代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns="mog.miss.component.*" xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
import mx.managers.IFocusManagerComponent;
private function focus():void{
focusManager.setFocus(commentTextInput as IFocusManagerComponent);
commentTextInput.setSelection(commentTextInput.text.length,commentTextInput.text.length);
}
]]>
</mx:Script>
<mx:TextInput id="commentTextInput" creationComplete="{focus()}" />
</mx:Panel>
I'm trying to have a popup window with an immediately editable TextInput. This means that the user should be able to type inside the TextInput once the popup is displayed.
The problem is that I can't focus on the textInput. What happens is that when pressing a key for the first time, no text is inserted, only after a second key is pressed does the component gain focus and the user is able to type. For instance, typing "test" once the popup opened results in "est" being displayed...
For some reason the component only gains focus when the user explicitly clicks on it or types something. Programmaticaly setting the focus does not work.
Any ideas/suggestions?
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns="mog.miss.component.*" xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
import mx.managers.IFocusManagerComponent;
private function focus():void{
focusManager.setFocus(commentTextInput as IFocusManagerComponent);
commentTextInput.setSelection(commentTextInput.text.length,commentTextInput.text.length);
}
]]>
</mx:Script>
<mx:TextInput id="commentTextInput" creationComplete="{focus()}" />
</mx:Panel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题是我用 F10 键触发了弹出调用。 F10 是系统保留的...它确实触发了处理程序并创建了弹出窗口,但不知何故应用程序失去了焦点。使用另一把钥匙修复了它。唯一的保留键是 F10。 更多信息
The problem was that I was triggering the popup call with the F10 key. The F10 is system reserved... it did trigger the handler and the popup was created but somehow the application lost focus. Using another key fixed it. The only reserved key is F10. More about that
这取决于你如何尝试去做。对我有用的是处理弹出窗口的creationComplete事件:
PS:示例中的“处理程序”是通过mxml添加的,因此它没有参数。
It depends on how you try to do it. What works for me is handling the creationComplete Event of the popup:
PS: The "handler" in the example is added via mxml so it has no parameters.
这对我有用。在弹出窗口的
creationComplete
事件中:Here's what works for me. In the
creationComplete
event of the pop up window:就我而言,我刚刚在自定义组件中实现了 IFocusManagerContainer,一切正常
private var _defaultButton:IFlexDisplayObject = /default component/;
in my case i just implemented IFocusManagerContainer in my custom component and everything worked fine
private var _defaultButton:IFlexDisplayObject = /default component/;