开发者

Flash - Mouse Event Handling (Make symbol transparent to mouse)

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 bu开发者_运维知识库t 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜