Author Topic: Getting Button that called function  (Read 1656 times)

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
Getting Button that called function
« on: August 29, 2014, 10:24:24 PM »
Hello,
I love how easy it is to have a button in NGUI call a function on its click event.  What I am wondering is how can I have multiple buttons call the same function and in the function know which button the call came from?  I have a big scroll view list of about 50 buttons, and so it would be nice to have 1 function that all the buttons call and inside the function know which button called it and then handle the event accordingly.

I would think there has to be a way to do this?  Can I add some type of parameter to the function that will accept the button object that calls it?

any help would be great, thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Getting Button that called function
« Reply #1 on: August 30, 2014, 09:28:55 AM »
UIButton.current tells you which button it came from. It's the same with any NGUI event. UISlider.current, UIToggle.current, UICamera.current, etc.

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
Re: Getting Button that called function
« Reply #2 on: September 01, 2014, 12:20:36 PM »
Thank you, that works great.