焦点问题,焦点有时会转向未知物体
[FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
当我用鼠标单击 TextField 时,我希望另一个(可编辑)字段获得焦点,但当前焦点迷失在某处..我不知道焦点在哪里。
我创建了一个文本字段监听器,它尝试将焦点设置回另一个带有 stage.focus = editfield 的字段,但它不起作用。
我在舞台上也有相同的焦点听众,但没有区别。
[FocusEvent type="focusIn" bubbles=true cancelable=false eventPhase=3 relatedObject=null shiftKey=false keyCode=0]
When I click with a mouse an TextField, I would like that another (editable) field gets focus, but currently focus is lost somewhere.. I dont know where focus is.
I made a listener to textfield which tries to set focus back to another filed with stage.focus = editfield but its not working.
I have also same focus listener in stage, but no difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您在示例中列出了“FocusEvent”,因此我将重点介绍 Flex 解决方案。 那不是 Flash AS3 类。
我敢打赌 Flex 正在尝试自行管理焦点,这会破坏您设置焦点的尝试。 然而,有很多方法可以解决这个问题。
Flex 是否试图与您作对?
首先,您可能想要使用 FocusManager 类或 UIComponent setFocus 方法(这取决于您具体需要做什么,我相信 FocusManager 允许您定位多个对象,而 setFocus 方法要简单得多)而不是舞台.焦点. 这样做的好处是可以在 Flex 组件系统中本地工作。
您正在收听正确的事件吗?
如果失败,请尝试确保您正在查找的 FocusEvent 的目标既不是您的文本字段,也不是您的文本字段的子级。 (只是为了理智)。 如果这不起作用,请确保您只调度一次事件。接下来,我将尝试使用 MouseEvent.CLICK 而不是 FocusEvent。
其他一切都失败了吗?
不幸的是,Flex 通常远非完美。 我发现有时我必须使用 setTimeout 来解决它不会以“正确的顺序”触发事件的事实 - 您调整某些内容的大小,但“RESIZE”在重新渲染之前被调度,您更改字体,并且 TextArea 的 TextWidth 属性不会返回正确的数字。 解决方法
Since you list a "FocusEvent" in your example, I will focus on Flex solutions. That is not a Flash AS3 class.
I will wager that Flex is trying to manage the focus by itself and that is screwing with your attempts to set it. There are, however, a number of ways around this.
Is Flex trying to work against you?
First, you may want to either use FocusManager class or the UIComponent setFocus method (this depends on what you specifically need to do, I believe the FocusManager allows you to have multiple objects targeted, while the setFocus method is a good deal simpler) instead of stage.focus. This has the benefit of working natively within the Flex component system.
Are you listening to the right event?
Failing that, try making sure that the target of the FocusEvent you're looking for is neither your textfield nor a child of your textfield. (Just for sanity's sake). If that does not work, make sure you are only getting the event dispatched once.Next, I would try using MouseEvent.CLICK instead of a FocusEvent.
Has everything else failed?
Unfortunately, Flex is often far from perfect. I find that sometimes I have to use setTimeout to get around the fact that it does not fire events in the "right order" -- you resize something, but "RESIZE" is dispatched before it has re-rendered, you change the font, and a TextArea's TextWidth property doesn't return the right number. The workaround