views:

989

answers:

2

Is there a way to write a custom event that gets triggered when the user clicks outside of that custom component instance? Basically anywhere else in the main flex app. Thanks.

+1  A: 

You can use the FlexMouseEvent.MOUSE_DOWN_OUTSIDE event. For example:

myPopup.addEventListener(
   FlexMouseEvent.MOUSE_DOWN_OUTSIDE,
   function(mouseEvt:FlexMouseEvent):void
   {
       PopUpManager.removePopUp(myPopup);
   }
);
Jacob
the FlexMouseEvent.MOUSE_DOWN_OUTSIDE is however just broadcast if you add the component with the popupmanager, not if you do a manual addChild (see http://www.mail-archive.com/[email protected]/msg14875.html and see my last hour of hair-pulling)
iddqd
A: 
stage.addEventListener( MouseEvent.CLICK, stgMouseListener, false, 0, true );

...

private function stgMouseListener( evt:MouseEvent ):void
{
    trace("click on stage");
}


private function yourComponentListener( evt:MouseEvent ):void
{
    trace("do your thing");
    evt.stopPropagation();
}
jedierikb