views:

880

answers:

2

Hi,

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

+1  A: 

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
Zed-K
Hi, Thanks for the answer.Perhaps I didn't explain myself well enough. What I mean is that I have 2 sprites connected to the stage.1) A background that fills the entire stage.2) A sprite that is attached to the stage as well.Now, both symbols (bg/sprite) respond to 'click'.I want transparent pixels to basically get ignored and pass the click right through to the background. Thanks again
Alon
Since you use the term "symbols", I suppose they are created in Flash IDE and not programmatically, right? If it's the case, I don't see how to use this method, since I don't know how to access the Bitmap object inside the symbol (I'm not quite used to work with Flash and its librairy =/) By the way, are you using AS2 or AS3?
Zed-K
We're using AS3. Actually its a mix, we're using Flash to export our symbols and Flex Builder to program in.If you're interested in what was actually wrong I wrote it below,My fix was to make the PlayerSprites a child of the background.This way if a mouse event is ignored by a player sprite symbol, the background is still within the event route and gets processed.Thanks for your help :)
Alon
A: 

Hi,

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.

Alon