PDA

View Full Version : stopImmediatePropagation



lope
January 21st, 2010, 09:22 AM
I have listener added to the stage like so:

stage.addEventListener(MouseEvent.MOUSE_DOWN, whatever);

I also have a few buttons on the stage.
now when i click the button i dont want for a stage to reveive mouse_down event, is it possible somehow?

i tried putting e.stopImmediatePropagation() in my button click function but it doesnt do the trick...

[MuG]
January 21st, 2010, 09:37 AM
I imagine the reason why your e.stopImmediatePropagation() isn't working is that you're button listeners are lower down in the node list. IE the event fires from the button down to the stage and then back up to your listeners.... If that makes sense :S

I find that having a listener on the stage is generally not a good idea for the reason you stated. There are a few things you could do depending on why you're listening to the stage events.

Probably the easiest thing to do is to make a check in the stage listener:


stage.addEventListener(MouseEvent.MOUSE_DOWN, whatever);

function whatever(e : MouseEvent) : void {
if (e.currentTarget is SimpleButton) {
// Do nothing: The event was fired from a button click
} else {
// Run the normal code.
}
}


I think that should work