可点击的手绘组件的最简单祖先?
我正在创建一个将是一个很大的加号或一个很大的减号的组件。我不想使用位图,因为即使我可以使用 Graphics 类来绘制它,但该组件必须是可单击的(Shape 类不是)。
它将成为项目渲染器的一部分,因此我希望它尽可能轻量。 UIComponent 似乎没有发送 CLICK 消息。
感谢您的任何想法
I am creating a component that will be a large plus or a large minus. I don't want to use a bitmap because even I can draw this using the Graphics class, but the component must be clickable (the Shape class is not).
It will be part of an item renderer, so I want it to be as light-weight as possible. UIComponent does not seem to sent CLICK messages.
Thanks for any ideas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你看这里:
UIComponent Docs
您将看到 UIComponent 在中具有 InteractiveObject它的继承路径。 InteractiveObject是添加鼠标事件功能的类。
If you look here:
UIComponent Docs
You will see that UIComponent has InteractiveObject in its inheritance path. InteractiveObject is the class that adds mouse event functionality.
UIComponent 实际上会调度点击事件。但是,如果图形上没有绘制任何内容,则 UIComponent 将没有可单击的区域。如果您绘制的加号或减号图标太小而无法可靠地捕捉鼠标活动,则绘制一个完全透明的矩形以增加点击区域。
UIComponent will actually dispatch click events. However, if there is no content drawn to the graphics, the UIComponent will have no area that can be clicked. If the plus or minus icon you draw is too small to reliably catch mouse activities, then draw a fully-transparent rectangle to increase the hit area.
我建议创建一个 Sprite 对象并将减号和加号箭头绘制到其图形对象。然后你必须 addEventListener(MouseEvent.CLICK, someFunction);在它的构造函数中或任何您需要它的地方。
此时您可能还需要将cacheAsBitmap 设置为true,这样就不会每帧都重新绘制。
编辑:根据@jeremynealbrown,如果你在 Flex 中工作,显然你必须使用 SpriteAsset 类。非常相似,但添加了另外 2 个抽象级别。
I would suggest creating a Sprite object and drawing the minus and plus arrows to its graphics object. You'll then have to addEventListener(MouseEvent.CLICK, someFunction); in its constructor or wherever else you'll need it.
You may also want to set cacheAsBitmap to true at that point, so that it's not redrawn every frame.
EDIT: Per @jeremynealbrown you have to use the SpriteAsset class if you are working in Flex, apparently. Very similar, but another 2 levels of abstraction are added.