Author Topic: How to detect clicking outside of an area?  (Read 2599 times)

MegaX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
How to detect clicking outside of an area?
« on: April 08, 2014, 07:19:57 PM »
So I've been working on a chat feature for my game. The chat box background is hidden normally. It shows up when you hit Enter and then you're allowed to type in something to send. The desired effect is when you click somewhere outside of the box, the background becomes hidden again.

I binded Enter to select the input field and show the background, easy. But I'm having trouble hiding the background correctly. Using the scroll bar as well as clicking inside the chat box shouldn't hide the background. I've tried a bunch of different stuff, nothing really worked. How should I approach this?

The first image is the normal one, input field and background hidden, can't chat.
The second image is after you hit Enter, background shows up, you can type in the input field.
« Last Edit: April 08, 2014, 09:16:55 PM by MegaX »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to detect clicking outside of an area?
« Reply #1 on: April 09, 2014, 03:26:12 AM »
Whenever you click on something, that "something" gains the selection, and whatever was selected before loses the selection. This means that the latter receives OnSelect(false), and the former then receives OnSelect(true). Since you are typing in an input field, the input field is what has focus. The input field will get OnSelect(false) when it loses focus -- so just have a script listen for that.

MegaX

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: How to detect clicking outside of an area?
« Reply #2 on: April 09, 2014, 12:52:46 PM »
Yes, I understand that. The problem is that if I click on the scroll bar and scroll the text, that sends a OnSelect(false) to the input field as well. But in that case, I don't want to do anything.