Reputation: 858
I have a popup and i want to close it on mouse outside click. so i made a listener of event MouseDownOutside
. but it listen only left click. i also want to close it to a right click but if i make a right click on popup then it should be opened. i searched on google but second time it hasn't any solution. Does anybody know a way to close the popup?
so creation Code of a popup Looks Like
var myPopUp:CustomComponentClass = new CustomComponentClass();
PopUpManager.addPopUp(myPopUp, Parent, true);
PopUpManager.centerPopUp(myPopUp);
Closing the popup
PopUpManager.removePopUp(myPopUp);
Thanks In Advance
Upvotes: 1
Views: 240
Reputation: 13532
I would try something like this :
stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN,onRightMouseDown);
function onRightMouseDown(e:MouseEvent):void
{
var point:Point = popup.globalToLocal(new Point(stage.mouseX,stage.mouseY));
if(!pointInside(popup,point))
{
PopUpManager.removePopUp(popup);
}
}
The pointInside function just checks if point is inside the rectangle of the popup.
public function pointInside(obj:DisplayObject, point:Point):Boolean
{
return (point.x >= 0 && point.y >= 0 && point.x <= obj.width && point.y <= obj.height);
}
Upvotes: 1