开发者

FlexMouseEvent.MOUSE_DOWN_OUTSIDE works only for pop-up component?

I have a component that extends UIComponent of Flex, I want to add it a Fl开发者_Go百科exMouseEvent.MOUSE_DOWN_OUTSIDE listener but it does not works. that means I can not capture the event. But when I use PopUpManager to add this component, and then add a FlexMouseEvent.MOUSE_DOWN_OUTSIDE listener, it works fine.

Is FlexMouseEvent.MOUSE_DOWN_OUTSIDE only works for pop-up components?

Thanks for helping


That event only fires through popups. If you want to check a mouse event you need to add the regular mouse down to the parent container and check if the target is NOT the child.

Another way you can do this is by catching the event on the stage and on the component... Since bubbling goes upwards, the component click gets caught first.

public var bCompClicked=false;

stage.addEventListener(MouseEvent.CLICK,onStageClick);
myComponent.addEventListener(MouseEvent.CLICK,onComponentClick);

private function onComponentClick(event:MouseEvent):void{
     bCompClicked = true;
}

private function onStageClick(event:MouseEvent):void{
     if(!bCompClicked){   //we didn't click the component, so we clicked outside it..
       clickedOutSide();
     }else{
        bCompClicked=false; //we did click the component, set to false for the next time.
     }
}

private function clickedOutSide():void{
    //do what you want when someone clicks outside...
}

Disclaimer I haven't tested this or thought about it very hard... so it may not work.


This is a follow up on the answer from Jonathan, with a single handler, and taking care of child components if any.

stage.addEventListener(MouseEvent.CLICK,onStageClick, false, 0, true);

private function onStageClick(event:MouseEvent):void
{
  var object:Object = event.target;
  while (object && object != this && object.hasOwnProperty("parent")) {
    object = object.parent;
  }
  if (object != this) {
    // the click is not from this component or its children
  }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜