Flash - 鼠标事件处理(使符号对鼠标透明)
我有一个带有背景符号的闪光灯,可以响应“点击”事件。 在该符号的顶部,我有一个精灵,其中包含带有透明像素的位图。 两者都是添加到舞台上的,所以没有直接关系。
我希望点击精灵上的透明像素可以直接进入背景。
我已经阅读过有关 mouseEnabled / mouseChildren 的内容,但无法使这些工作起作用。 当我使用符号时,该符号会忽略鼠标事件,但不会像透明一样传递它。
这可以用闪光灯来做吗?或者我必须重新路由鼠标事件?
谢谢
I have a flash that has a background symbol that responds to CLICK event.
On top of that symbol I have a sprite that contains a Bitmap with transparent pixels.
Both of them are added to the stage, so they are not related directly.
I want clicks on the transparent pixels on the sprite to go straight through to the background.
I have read about mouseEnabled / mouseChildren but have not been able to make these work.
The symbol ignores the mouse events when I use them, but does not pass it along as if its transparent.
Is this possible to do with flash? Or will I have to re-route mouse events?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在位图上添加一个侦听器(无需将位图包装在 Sprite 中)来侦听 MouseEvent.CLICK 事件。
然后,在您的点击处理函数中,只需使用 getPixel32 来获取点击像素的 alpha :
You can add a listener on your Bitmap (no need to wrap your Bitmap inside a Sprite) to listen for the MouseEvent.CLICK event.
Then, in your click handler function, just use getPixel32 to get the alpha of the clicked pixel :
我意识到问题是什么。
我的场景是这样构建的:
舞台 ->容器#1 ->容器#2 ->玩家精灵
->背景
将玩家精灵标记为 mouseEnabled = false / mouseChildren = false 实际上会禁用鼠标。
然而到那时,鼠标事件位于容器#2中,因此它不会以“透明”方式到达背景符号。
I realized what the problem is.
My scene is built like this:
stage -> container #1 -> container #2 -> PlayerSprites
-> Background
Marking the player sprites as mouseEnabled = false / mouseChildren = false does in fact disable the mouse.
How ever by that time, the mouse event is in container #2, Because of this it will not reach the background symbol in a 'transparent' manner.