closing PopUp when clicked outside of it

hi guys

I have a scenario where i am using

PopUpManager.addPopUp(dataGrid, this, false);

If user clicks on the screen anywhere outside of the popup, the popup should close.

any idea if that is possible?

thanks
royjaydAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgofmanCommented:
add listener for your DataGrid instance

dataGridPopup.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, closePopup);

private function closePopup(event:FlexMouseEvent):void {
      PopUpManager.removePopUp(dataGridPopup);    
}
dgofmanCommented:
forgot to delete listener


private function closePopup(event:FlexMouseEvent):void {
      event.currentTarget.removeEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, closePopup);
      PopUpManager.removePopUp(dataGridPopup);    
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royjaydAuthor Commented:
Is it must to impliment the removeEventListener() everytime when we do addEventListener ?

thanks
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

dgofmanCommented:
royjaydAuthor Commented:
just curious
If i have VBox insteaad of Popup , should i say

public class DetailsGrid extends VBox
public function DetailsGrid (){
this.addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, closeDetailGridopup);
}
private function closeDetailGridopup(event:FlexMouseEvent):void {
      event.currentTarget.removeEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, closeDetailGridopup);
      removeChild(this);  -- if i want to remove the Vbox , will this work?
}
}
dgofmanCommented:
You cannot remove the reference to your own object.
1) "this" is not children of "this" it's not make sense "this.removeChild(this);" - your father has child himself
2) When you are destroying the popup all references will be gone you don't need to remove any children  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.