Hello Guest

Author Topic: Event Bubbling Functionality in tk2d using UIItem Parent  (Read 5422 times)

daklab

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Daklab - Experiments, Projects, Designs, Tips, and Tutorials Related to Creative Coding
Event Bubbling Functionality in tk2d using UIItem Parent
« 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?
Braindrop Labs - Games. Apps. Coded Art. www.braindroplabs.com

daklab

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Daklab - Experiments, Projects, Designs, Tips, and Tutorials Related to Creative Coding
Re: Event Bubbling Functionality in tk2d using UIItem Parent
« Reply #1 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 :)
Braindrop Labs - Games. Apps. Coded Art. www.braindroplabs.com

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Event Bubbling Functionality in tk2d using UIItem Parent
« Reply #2 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.