Flash - 鼠标事件处理(使符号对鼠标透明)

发布于 2024-08-19 18:45:24 字数 256 浏览 3 评论 0原文

我有一个带有背景符号的闪光灯,可以响应“点击”事件。 在该符号的顶部,我有一个精灵,其中包含带有透明像素的位图。 两者都是添加到舞台上的,所以没有直接关系。

我希望点击精灵上的透明像素可以直接进入背景。

我已经阅读过有关 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯了 2024-08-26 18:45:24

您可以在位图上添加一个侦听器(无需将位图包装在 Sprite 中)来侦听 MouseEvent.CLICK 事件。

然后,在您的点击处理函数中,只需使用 getPixel32 来获取点击像素的 alpha :

var alpha:String = ( yourBitmap.BitmapData.getPixel32( e.localX, e.localY ) >> 24 & 0xFF).toString(16);
if( alpha == "0" )
    // Trigger your symbol click handler here

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 :

var alpha:String = ( yourBitmap.BitmapData.getPixel32( e.localX, e.localY ) >> 24 & 0xFF).toString(16);
if( alpha == "0" )
    // Trigger your symbol click handler here
莫言歌 2024-08-26 18:45:24

我意识到问题是什么。

我的场景是这样构建的:

舞台 ->容器#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文