FLEX:UIComponent 单击处理程序?
感谢您的阅读。
我正在尝试将标签和图像并排放置在 UIComponent 上。出于效率原因我想使用 UIComponent,整个组件比仅仅一个带有图标的按钮更复杂。
我试图在整个 UIComponent 上获取一个单击处理程序,以便当在标签或图像上发生单击时,会调用相同的 [click] 事件处理程序。如果我在根组件上添加单击处理程序,它就可以工作,但是当我在标签和图像之间引入空间时,它们之间的空间将变得不可单击。我通过对标签和图像使用 move(x,y) 方法来生成空间,其中 x/y 坐标之间有一个小间隙。
有什么想法可以解决这个问题吗?
谢谢。
Thanks for reading.
I'm trying to put a label and an image on a UIComponent, side-by-side. I want to use UIComponent for efficiency reasons, and the entire component is more complicated than just a button with an icon.
I'm trying to get a click handler on ther entire UIComponent so that when a click happens on either the label or the image, the same [click] event handler is called. If I add a click handler on the root component, it works, but when I introduce space between the label and the image, the space between them becomes un-clickable. I produce the space by using the move(x,y) method for the label and the image with a small gap between the x/y coordinates.
Any ideas how to remedy this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于 invertedSpear 的答案,这不是一个错误,而是已知的行为。在某些情况下,您不希望容器的背景捕获点击,而此行为允许您控制它。
invertedSpear 是正确的,UIComponent 不处理自己的背景样式。您可以绘制自己的透明背景来捕获鼠标事件:
With regard to invertedSpear's answer it is not a bug, it is known behaviour. There are situations when you do not want a container's background to capture clicks and this behaviour allows you to control that.
invertedSpear is correct that the UIComponent does not handle its own background styles. You can draw your own transparent background to capture the mouse events:
我认为 UI 组件在处理点击时遇到与画布(从 UI 组件扩展)相同的问题。当您单击画布时,除非您为该画布提供背景,否则不会发生任何事情,即使您将 Alpha 设置为 0(完全透明)。这是 Adobe 知道但尚未修复的错误,其想法是没有 BG 实际上意味着那里什么也没有。只要给它背景就可以点击。现在不幸的是 UIComponent 没有任何背景样式,您可以切换到画布吗?另一种选择可能是在 UIComponent 中包含图像,将其 alpha 设置为 0,将高度和宽度设置为 100%
I think that a UI component suffers from the same problem that the canvas (which extends from the UI component) does when handling clicks. When you click on a canvas nothing happens unless you give that canvas a background, even if you set the alpha to 0 (fully transparent). This is a bug that Adobe knows about but hasn't fixed yet, the idea being that having no BG actually means that there is nothing there. Just giving it that background makes it clickable. Now unfortunately the UIComponent does not have any background styles, can you switch to a canvas? Another alternative might be to include an image in the UIComponent, set the alpha of that to 0 and the height and width to 100%
你可以试试 mx:Spacer 吗?尽管 UIComponent 不是容器,但这可能是您的问题。您可以尝试扩展 mx.core.Container,而不是使用 UIComponent。但首先尝试垫片。
编辑:我越想这个,我就越认为垫片会起作用。对于 UI 组件单击处理程序,真正发生的是 UI 组件中的各个元素正在注册单击并且它们正在冒泡。当您进行移动时,就像建议的其他答案一样,实际上没有任何东西可以记录点击。垫片应该可以解决这个问题,而且更容易。
You could try mx:Spacer instead? UIComponent isn't a container though, that might be your problem. Instead of using UIComponent, you could try to extend mx.core.Container. But try the spacer first.
Edit: The more I think about this the more I think the spacer will work. For the UI component click handler, what is really happening is the individual elements in the UI component are registering clicks and they are bubbling up. With you doing a move, like the other answer suggested, there really isn't anything there to register the click. The spacer should solve that problem, and easier.