Grabbing "touch" API info

On the API reference page, under the “touch” event I see a few options:

event.id
event.name
event.phase
event.target
etc…

I am definitely using event.phase correctly, but I’m not sure what I’m doing different with the others.

local function runFunction(e)  
 print("id: "..e.id); --does not seem to return anything  
 print("target"..e.target); -- does not return anything  
 print("name: "..e.name); --returns "touch"  
end  
  
Runtime:addEventListener("touch", runFunction);  

Should the “id” and “target” be displaying something?

Also, if I want to log the name of the element (or button name) that is touched, how would I do that?

For example, I may have 2 buttons that call the same function. I would love to know which button was pressed in the function.

[code]
local function runFunction(e)
print(“show which button I pressed, and any others I may introduce later”);
end

button1:addEventListener(“touch”, runFunction);
button2:addEventListener(“touch”, runFunction);
[/code] [import]uid: 154122 topic_id: 27389 reply_id: 327389[/import]

Hey Marc,

I believe id is used with ui.lua.

For e.target that isn’t returning anything because you were using a Runtime listener. If you added that line in your second function it would print the target.

If you want to make it clear for yourself I’d do something like this;
[lua]–Button 1
local btn1 = display.newCircle( 100, 100, 30 )
btn1.name = “button 1”

–Button 2
local btn2 = display.newCircle( 220, 100, 30 )
btn2.name = “button 2”

–Tap function
local function tapBtn(event)
print ("target: "…event.target.name)
end
btn1:addEventListener(“tap”, tapBtn)
btn2:addEventListener(“tap”, tapBtn)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 27389 reply_id: 111275[/import]