How to check which image is clicked/tapped/touched

Hi,

I need to display 50 images on IPad screen.

Am I able to addEventListener to the same function listener?

button:addEventListener(“touch”, listener)
button2:addEventListener(“touch”, listener)
button3:addEventListener(“touch”, listener)
.
.
button50:addEventListener(“touch”, listener)

If yes, inside listener function, how do I track which image/button is clicked/tapped/touched?

Thanks, [import]uid: 32376 topic_id: 6294 reply_id: 306294[/import]

You can do that, yes. The event object sent to the listener includes a “target” parameter that is the object tapped on:

local function listener(event) if event.target == button then print("button") end end [import]uid: 12108 topic_id: 6294 reply_id: 21693[/import]

Or add a custom property to each button like an ID and check that. [import]uid: 5712 topic_id: 6294 reply_id: 21732[/import]

jhocking,

Thanks :slight_smile:

MikeHart,

Is there any sample /tutorial on custom properties? [import]uid: 32376 topic_id: 6294 reply_id: 21737[/import]

Adding a custom property is as simple as typing

button.id = 1 [import]uid: 12108 topic_id: 6294 reply_id: 21739[/import]