Find out which object was touched?

Hello,

I have a series of images on screen and I’d like to create one event listener and one function to print which object was touched.

How do I do this please?

Thanks

Tom [import]uid: 55068 topic_id: 10623 reply_id: 310623[/import]

[lua] local function detect(e)
–this e.target is ur target and u can access all the properties of that
print(e.target.myName)
e.target:setFillColor(math.random(255),math.random(255),math.random(255))
end

local button1 = display.newRect(0,0,100,50)
button1.myName = “button1”
local button2 = display.newRect(150,0,100,50)
button2.myName = “button2”
local button3 = display.newRect(0,100,20,50)
button3.myName = “button3”
button1:addEventListener(“tap”,detect)

button2:addEventListener(“tap”,detect)
button3:addEventListener(“tap”,detect)[/lua] [import]uid: 12482 topic_id: 10623 reply_id: 38664[/import]