Capturing tap and touch events

I have a button, created using the widget module, it overlaps another object. The tap event passes through activating both objects. How can I capture the event before it passes through to the object below? [import]uid: 98652 topic_id: 19215 reply_id: 319215[/import]

You need to add “return true” to the end of your event listener. [import]uid: 10903 topic_id: 19215 reply_id: 74096[/import]

Thanks for the reply. I tried this and it didn’t seem to work. At least with the widget button. Seems the release/touch up still passes through to the object below. [import]uid: 98652 topic_id: 19215 reply_id: 74218[/import]

Can you post up some code ? Thanks [import]uid: 84637 topic_id: 19215 reply_id: 74764[/import]

I’m using the widget library to make a button. Beneath this are some rectangles made with display.newrect().

-- Make a button with widget
function make\_start\_button() 
 start\_btn = widget.newButton({id="start",
 left=display.contentWidth \* .05,
 top=display.contentHeight/2,
 width=display.contentWidth \* .90,
 height=display.contentHeight \* .12,
 onEvent=on\_start\_button })
end
-- make some squares to tap
local square = display.newRect(0, 0, square\_size, square\_size)
square:setReferencePoint( display.TopLeftReferencePoint )
square.color = "white"
square:setFillColor(255, 255, 255)
square:addEventListener("tap", on\_tap)

[import]uid: 98652 topic_id: 19215 reply_id: 74769[/import]

Are you using display groups? [import]uid: 84637 topic_id: 19215 reply_id: 75174[/import]

Inside on_tap function you should have this.
local function on_tap()

if event.phase == “began” then

>>do something here<<

end
return true
end

If you do the above then the square will not pass to object behind.

KC
[import]uid: 94613 topic_id: 19215 reply_id: 75212[/import]