Event Listeners

I’ve got a question about layering images/buttons with Corona/Lua. If I create one button on top of another one and then click it, both buttons’ events are triggered. How do I prevent this? … I want 

 Thank You.

Code: here is the functions that goes to the scenes.

local function onSceneTouch(event) 

    print(event.name…" occurred") 

    storyboard.gotoScene(“help”, “fade”, 400)

    return true

    

end

local function onSceneTouchS(event) 

    print(event.name…" occurred") 

    storyboard.gotoScene(“specials”, “fade”, 400)

    return true

    

end

HERE IS THE BUTTONS

 b_help = display.newImage(“buttons/help.png”)

     b_help.x = 190

     b_help.y = 250

     screenGroup:insert( b_help )

     b_help:addEventListener(“touch”, onSceneTouch)

    

     b_thanks = display.newImage(“buttons/thanks.png”)

     b_thanks.x = 190

     b_thanks.y = 310

     screenGroup:insert( b_thanks )

     b_thanks:addEventListener(“touch”, onSceneTouchS)

Hmm, maybe try and change them from touch to tap listeners? Unless you have a good reason for them to be touch.

Touch events call the function if the touch began, if the touch moves and if the touch ended. 

Try this:

b\_help:addEventListener("tap", onSceneTouch) b\_thanks:addEventListener("tap", onSceneTouchS)

that is  slightly working… but now the problem is the both of the buttons are just calling the same scene instead of their assigned scenes e.g.

both buttons call the the “specials scene” instead of calling the “help scene”   do you know what might be the wrong here?

Thank you 

Hmm, you mentioned the buttons are layered on top of each other, it sounds like the top most button is taking your touch event. You may need to space the out a little.

Thank you for your help… 

for some reason I can’t figure out to work the buttons… but instead of using buttons I am just going to use text… seems to be working better… 

Thank you once again

Hmm, maybe try and change them from touch to tap listeners? Unless you have a good reason for them to be touch.

Touch events call the function if the touch began, if the touch moves and if the touch ended. 

Try this:

b\_help:addEventListener("tap", onSceneTouch) b\_thanks:addEventListener("tap", onSceneTouchS)

that is  slightly working… but now the problem is the both of the buttons are just calling the same scene instead of their assigned scenes e.g.

both buttons call the the “specials scene” instead of calling the “help scene”   do you know what might be the wrong here?

Thank you 

Hmm, you mentioned the buttons are layered on top of each other, it sounds like the top most button is taking your touch event. You may need to space the out a little.

Thank you for your help… 

for some reason I can’t figure out to work the buttons… but instead of using buttons I am just going to use text… seems to be working better… 

Thank you once again