How to close menu when touch outside of it?

I have made a menu and I want to close it if I touch anywhere outside of the menu. May I know how can I do that?

I think the link above would be useful to you.