Getting the Name of the object on a Touch Event

Hi,

I have the following function, that I want to reuse

function clock:touch(e)  
 if (e.phase == "began") then  
 -- doSomething   
 elseif(e.phase == "ended") then  
 --doSomething   
 end   
end  
  
clock:addEventListener("touch", clock);  
  

Can i reuse the code on multiple objects, by getting the name of the object touched? dog:addEventListener(“touch”, clock);

Is it possible to get the name of the object “touched”, right now i know you can get the name of the event.

Thanks

[import]uid: 120979 topic_id: 21406 reply_id: 321406[/import]

Yes it’s possible… Look at the Corona API, Share Your Code - http://developer.anscamobile.com/code/ or http://www.learningcorona.com/

Same questions again and again :confused:
[import]uid: 12704 topic_id: 21406 reply_id: 84764[/import]

@gtatarkin come on… be nice :o)

@garimellaravi

yes you can do something like this:

[lua]local function eventListener ( e )
if e.phase == “began” then
print ( e.target.name )
end
end

local c = display.newCircle ( 100, 50, 30)
c.name = “circle”
c:addEventListener ( “touch”, eventListener )

local b = display.newRect ( 200, 50, 60, 60)
b.name = “box”
b:addEventListener ( “touch”, eventListener ) [import]uid: 13632 topic_id: 21406 reply_id: 84768[/import]

Ha Ha,

Thanks.

Apparently my search of the forums did not yield this result.

Also coming from AS, i was assuming automatic naming vs explicit naming. [import]uid: 120979 topic_id: 21406 reply_id: 84771[/import]