該事件僅通過彈出窗口觸發。如果您想檢查鼠標事件,則需要將常規鼠標添加到父容器,並檢查目標是否爲不是孩子。
另一種方法是通過捕獲舞臺上和組件上的事件......由於冒泡向上,組件點擊首先被捕獲。
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...
}
免責聲明我沒有測試過這種或想過這個問題很難...所以它可能無法正常工作。
嗯,它是一個功能,允許關閉組件點擊外部組件。 – xwgou