VBox 上未触发 Flex 鼠标滚轮事件
我在 VBox 的鼠标滚轮滚动方面遇到问题。当鼠标悬停在 VBox 中的任何组件或垂直滚动条上时,它可以正常工作,但当鼠标悬停在 VBox 的背景上时,不会发生滚动。
<mx:VBox width="100%" height="150">
<s:Label text="A large label." height="100" />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A large label." height="100" />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
</mx:VBox>
我查看了 VBox 和 Container(VBox 继承的)的代码。当存在垂直滚动条时,Container 会向自身添加一个 MouseEvent.MOUSE_WHEEL 侦听器。我在这个函数中放置了一个断点,但只有当我的鼠标位于子组件上时才会调用它。
作为最后的努力,我尝试设置 mouseEnabled、focusEnabled 和其他一些随机属性,但这些都没有帮助。
有谁知道如何使 VBox 正确运行并在我的鼠标位于其上的任意位置时滚动?提前致谢。
(由于不需要的捕捉行为,目前无法切换到 Spark Scroller。)
I'm having a problem with mouse wheel scrolling of a VBox. When the mouse if over any of the components in the VBox or the vertical scrollbar it works fine, but no scrolling occurs when the mouse is over the background of the VBox.
<mx:VBox width="100%" height="150">
<s:Label text="A large label." height="100" />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A large label." height="100" />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
<s:Label text="A label." />
</mx:VBox>
I looked at the code for VBox and Container (which VBox inherits.) Container adds a MouseEvent.MOUSE_WHEEL listener to itself when a vertical scroll bar exists. I put a breakpoint in this function but it's only called when my mouse is over a subcomponent.
As a last ditch effort I tried setting mouseEnabled, focusEnabled and a few other random properties but none of those helped.
Does anyone know how to make a VBox act correctly and scroll when my mouse is anywhere over it? Thanks in advance.
(Switching to a spark Scroller is not an option at the moment due to unwanted snapping behavior.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题(您可能已经猜到了)是 MouseEvents 没有触发。我怀疑 FocusEvents 也存在同样的问题。容器不会自行分派这些事件;他们只会从孩子那里得到事件;它接受鼠标和焦点事件。
作为一种解决方法,您可以尝试添加透明图像作为组件的第一个子组件。背景仍然会显示出来,但图像应该拾取相关事件并将它们冒泡到容器中。
Your problem--you may have guessed- is that the MouseEvents aren't firing. I suspect is the same issue with that exists with FocusEvents. Containers do not dispatch these events on their own; they only get events bubbled up from their children; which do accept mouse and focus events.
As one workaround, you may try adding a transparent Image as the first child to your component. The background will still show through, but the image should pick up the relevant events and bubble them up to the container.
一年前,我们遇到了类似的问题,鼠标滚轮滚动在 TabNavigator 上不起作用。在这里找到解决方法:
https://bugs.adobe.com/jira/browse/FP-289
和
https://bugzilla.mozilla.org/show_bug.cgi?id=448567
解决方案非常简单:在 flash start HTML 中删除以下行:
Year ago we had similar problem, that mouse wheel scroll did not work on TabNavigator. Found workaround here:
https://bugs.adobe.com/jira/browse/FP-289
and
https://bugzilla.mozilla.org/show_bug.cgi?id=448567
Solution was very simple: in flash start HTML removed following line: