Skip to main content
December 20, 2012
Question

Problem with listeners

  • December 20, 2012
  • 1 reply
  • 382 views

Hi,

I'm doing a flash mobile project with flash builder 4.6 and I'm finding some problems with listeners.

I have a view and until middle height I have a Skinnable container. I want to know when the user clicks outside the panel.

I mean, if the user clicks in the panel, I don't want to do anything, but if the user clicks on the view (not in the panel) I want to collect that event.

I've tried to use MouseEvent.MOUSE_DOWN, adding this listener to my view, but if you click on the panel, this event goes off too.

Do you know if there is any way to do this? Can I instruct the panel to listen the mouse down listener and don't pass it to the view?

Thanks in advance

This topic has been closed for replies.

1 reply

Participating Frequently
December 20, 2012

It's a bit hard to come up with a solution when there's no info about the layering, size and position of your view and panel. You can try to add something like this into your handler and see if the mouseDown is on the panel.

if(panel.hitPointTest(mouseX, mouseY, true)){

     /* do nothing */

}

else{

     /*do something */

}

Depends on the x and y of your panel, sometimes it's better to use stage.mouseX and stage.mouseY instead. And if your panel is a rectangle, just panel.hitPointTest(mouseX, mouseY) will be fine.

Hopefully this simple solution works for you. If not, I would imagine the panel need a listener that can somehow prevents the view's listener from firing. Or maybe the container of both the view and the panel will have to handle the event instead. Really depends on your structure. The best part is, there are so many ways to do the same thing in AS3. Good luck with it