我有一个扩展Flex的UIComponent的组件,我想添加一个FlexMouseEvent.MOUSE_DOWN_OUTSIDE监听器,但它不起作用。这意味着我无法捕获事件。但是,当我使用PopUpManager添加此组件,然后添加FlexMouseEvent.MOUSE_DOWN_OUTSIDE侦听器时,它工作正常。
FlexMouseEvent.MOUSE_DOWN_OUTSIDE仅适用于弹出式组件吗?
感谢您的帮助
答案 0 :(得分:5)
该事件仅通过弹出窗口触发。如果要检查鼠标事件,则需要将常规鼠标向下添加到父容器中,并检查目标是否为 NOT 该子项。
另一种可以做到这一点的方法是在舞台上和组件上捕捉事件......由于冒泡向上,因此首先捕获组件点击。
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...
}
免责声明我没有对此进行测试或认真考虑过......所以它可能无效。
答案 1 :(得分:0)
这是对Jonathan的答案的后续跟进,只有一个处理程序,并负责处理子组件(如果有的话)。
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
}
}