Touch handler question

Is there a convenient and easy way to share a touch handler among many similiar buttons?
For instance suppose I have an options panel that has many checkboxes on it. All the touch handlers for say 6 boxes are essentially the same, they simply make visible or invisible a checkmark on each box.
I can of course use x and y to determine which box was touched but is there an easier way?
I did see the event.id field that is passed in but I am not sure

  1. how to use it
  2. if I should use it
  3. is there an easier way to differentiate each touch?

Thanks,
-Dennis
[import]uid: 108253 topic_id: 19603 reply_id: 319603[/import]

you can write it like that:
[lua]local btn1 = …
btn1.name = “btn1”
local btn2 = …
btn2.name = “btn2”
local btn3 = …
btn3.name = “btn3”

local function onTouch(self, event)
if event.phase == “ended” then

if self.name == “btn1” then
print("i am button number one!toucha-toucha :slight_smile: ")
elseif self.name == “btn2” then

end
end
return true
end

btn1.touch = onTouch
btn1:addEventListener(“touch”, btn1)

–repeat[/lua]
[import]uid: 16142 topic_id: 19603 reply_id: 75721[/import]

wow nice!
I even made it a tad simpler. I substituted id for name and gave the id the index into a table.
Then in the handler I got self.id and used it to index into the checkBox array.
Amazingly simple. :slight_smile:
How did you figure that one out btw?
I assume it has to be named .touch for the table item to work?
Thanks so much. I knew it had to be easier.
-Dennis
[import]uid: 108253 topic_id: 19603 reply_id: 75725[/import]