2D Toolkit Forum

2D Toolkit => Support => Topic started by: daklab on October 30, 2013, 12:38:24 pm

Title: Event Bubbling Functionality in tk2d using UIItem Parent
Post by: daklab on October 30, 2013, 12:38:24 pm
In AS3 and JS (not UnityScript) I'm accustom to the concept of Event Bubbling. In essence, if I have a container with say 20 buttons, it is better to have a listener on the container as opposed to each button (1 listener vs. 20). The container is able to determine which child button was clicked via event bubbling.

I'm curious if something similar can be achieved in tk2d? I have a container GameObject with a tk2dUIItem attached. Within this container I have 20 buttons who currently each have tk2dUIItem components. I have the container capturing events via the Register Events From Children checkbox. My question is, is it possible for a container object (parent) to determine the child that was clicked within? If so, what part of the tk2d API do I need to be using (or look into more). Is there another way to achieve this?
Title: Re: Event Bubbling Functionality in tk2d using UIItem Parent
Post by: daklab on October 30, 2013, 01:19:44 pm
I'm still curious of your thought from my previous question, but I've at least found one solution that seems to work well so far. Raycast :)
Title: Re: Event Bubbling Functionality in tk2d using UIItem Parent
Post by: unikronsoftware on October 30, 2013, 07:54:02 pm
You can implement this yourself, fairly easily. Create a script that attaches to the UIItem (UIItemEventThingy) and hooks up to the relevant events. When any event occurs you can simply propagate upwards in the hierarchy to another instance of UIItemEventThingy, or you hit null. Use the ****UIItem variants of the functions (e.g. OnDownUIItem) to get the reference to the caller.