But with this code, all buttons display "Click 10" and not "Click 1" for the first, "Click 2" for the second. I think I have scope issue but I don't find a workaround.
Thanks for your help.
Title: Re: UIEventListener - Dynamic function
Post by: ArenMook on August 12, 2014, 06:59:11 AM
1. Never use Instantiate. Use NGUITools.AddChild instead. You are creating elements in the middle of nowhere with Instantiate.
2. You need to pass your 'i' as a function parameter argument, and use UIButton.onClick instead.
Title: Re: UIEventListener - Dynamic function
Post by: thibaud on August 12, 2014, 07:56:46 AM
Title: Re: UIEventListener - Dynamic function
Post by: ArenMook on August 13, 2014, 06:37:00 AM
UIEventListener functions expect the first parameter to be the game object. Check the class definition. UIEventListener is very limiting in this regard. This is why I suggested you to use the UIButton's onClick delegate instead.