learning events but setfocus or detecting touch/tap events on object not working

I’ve been trying to understand event handling but I have not been able to use the ‘setfocus’ command at all. i have two overlapping image objects. mmScreen is an image which is the whole iphone screen and the playBtn image is 200x60. The playBtn image is on top.

My issue is that I do not want the mmScreen listener to be invoked when i tap the ‘playBtn’. But it does… (on console, i see the print statement ‘touch printed out’) I’ve tried various combinations of setfocus method and it doesn’t do a thing. (its commented out in my code below)

Here is my code snippet:
[lua]menuScreenGroup:insert (mmScreen)
menuScreenGroup:insert (playBtn)

playBtn:addEventListener(“tap”, loadGame)
mmScreen:addEventListener(“touch”, testTouch)

end

function testTouch (event)
if event.target == “began” then
Num = Num + 1
print ("touched "… Num)
end
end

function loadGame(event)
if event.target.name == “playbutton” then
print (“tapped”)
–display.getCurrentStage():setFocus( self ) tried this and it didn’t work
transition.to(menuScreenGroup, {time = 300, alpha = 0, onComplete = addGamescreen})
playBtn:removeEventListener(“tap”, loadGame)
return true
end
end [lua]It is always something simple, so any help is appreciated. [import]uid: 179798 topic_id: 32833 reply_id: 332833[/import]

I see you are using return true, however it’s on tap and the mmScreen is listening for touch, not tap, so both will fire.

It would be worth taking a little read up on return true, IMHO.

Example below that will work;

[lua]–Background
local bg = display.newRect( 0, 0, 320, 480 )

–Button
local button = display.newCircle( 160, 300, 30 )
button:setFillColor(255, 0, 0)

–Tap the button
local function tapBtn()
print “1”
end
button:addEventListener(“tap”, tapBtn)

–Touch the background
local function touchBg(event)
if event.phase == “ended” then
print “2”
end
end
bg:addEventListener(“touch”, touchBg)

–Don’t let touch or tap events propogate
local function btnSafety()
return true
end
button:addEventListener(“touch”, btnSafety)[/lua]

PS - End lua tags with /lua not lua - will end code block. [import]uid: 52491 topic_id: 32833 reply_id: 130763[/import]

I see you are using return true, however it’s on tap and the mmScreen is listening for touch, not tap, so both will fire.

It would be worth taking a little read up on return true, IMHO.

Example below that will work;

[lua]–Background
local bg = display.newRect( 0, 0, 320, 480 )

–Button
local button = display.newCircle( 160, 300, 30 )
button:setFillColor(255, 0, 0)

–Tap the button
local function tapBtn()
print “1”
end
button:addEventListener(“tap”, tapBtn)

–Touch the background
local function touchBg(event)
if event.phase == “ended” then
print “2”
end
end
bg:addEventListener(“touch”, touchBg)

–Don’t let touch or tap events propogate
local function btnSafety()
return true
end
button:addEventListener(“touch”, btnSafety)[/lua]

PS - End lua tags with /lua not lua - will end code block. [import]uid: 52491 topic_id: 32833 reply_id: 130763[/import]

I have read 50% everything you’ve posted on your blog (techority), and that keeps me going (and of course this forum). I appreciate your nudge to read the documentation which I am doing. thank you for the example. :slight_smile: [import]uid: 179798 topic_id: 32833 reply_id: 130831[/import]

I have read 50% everything you’ve posted on your blog (techority), and that keeps me going (and of course this forum). I appreciate your nudge to read the documentation which I am doing. thank you for the example. :slight_smile: [import]uid: 179798 topic_id: 32833 reply_id: 130831[/import]

Thank you, I’m glad to hear Techority has been of use to you!

Hope the example proves helpful.

Peach :slight_smile: [import]uid: 52491 topic_id: 32833 reply_id: 131116[/import]

Thank you, I’m glad to hear Techority has been of use to you!

Hope the example proves helpful.

Peach :slight_smile: [import]uid: 52491 topic_id: 32833 reply_id: 131116[/import]

:& For the reason that upsides involving been able community providers have fallen as a possible vital requirement for business companies and also entities
http://www.certificationkey.com/HP-Certification-Training/HP2-E53.php [import]uid: 186858 topic_id: 32833 reply_id: 131193[/import]

:& For the reason that upsides involving been able community providers have fallen as a possible vital requirement for business companies and also entities
http://www.certificationkey.com/HP-Certification-Training/HP2-E53.php [import]uid: 186858 topic_id: 32833 reply_id: 131193[/import]