Multiple Layers with the same image

I seem to have a problem where I have multiple layers on screen that contain the same buttons even thou I have disabled them with removeEventListener

I have a problem where my code draws the screen by calling a function and activates some buttons with AddeventListener from a function. Then on tapping the buttons updates a global counter and calls a screen update via a function called PageSetUp() from within the button event function i.e(“Tap”).

I then wish to place a grid of buttons on screen to for quick access, but the buttons on the screen underneath are still active so I used a bunch of removeEventListener statements, this works to a point but if the clue 1 or 2 buttons have been used and the screen redrawn from the PageSetup() which updates the buttons with new images but all the names remain the same, it’s like each call of PageSetup() adds a transparent layer with the event Listeners.

Code summaries below (original about 800 lines so please read between the lines)

function pageSearch:tap( event )
print(“Function = pageSearch:Tap”)
media.playEventSound(pageSearchSID)
disableButtons()
pageNavigation()
–PageSetup()

end
local function PageSetup()

print("***You have entered the PageSetup()")

local background = display.newGroup()

–Display Main Image / Background
pageBackgroundImg = display.newImage(“pageFiles.png”)
buttonClue1= display.newText(bookCluesTextG[entryPageNo][1], 0, 0,clueFont , clue1FSize )
buttonClue2= display.newText(bookCluesTextG[entryPageNo][1], 0, 0,clueFont , clue1FSize )

background:insert(pageBackgroundImg)
background:insert(buttonClue1)
background:insert(buttonClue2)
end

local function ButtonSetup()

print("***You have entered the ButtonSetup()")

function pageSearch:tap( event )
disableButtons()
pageNavigation()
–PageSetup()

end

function buttonClue1:tap( event )
media.playEventSound(changeClueSID)
clueNo = 1
PageSetup()
end

function buttonClue2:tap( event )
media.playEventSound(changeClueSID)
clueNo = 2
PageSetup()
end

buttonClue1:addEventListener( “tap”, buttonClue1)
buttonClue1.bID = “buttonClue1”

buttonClue2:addEventListener( “tap”, buttonClue2)
buttonClue2.bID = “buttonClue2”

pageSearch:addEventListener(“tap”, pageSearch)
pageSearch.bID = “pageSearch”

end
PageSetup()
ButtonSetup() [import]uid: 5872 topic_id: 1066 reply_id: 301066[/import]

It’s hard to figure out the problem without the rest of the code, but if the basic issue is not having touches “fall through” to buttons underneath other buttons, then you should return true from the touch function to stop it from propagating to further objects underneath. [import]uid: 3007 topic_id: 1066 reply_id: 3104[/import]

Thanks I will try this.
I do have it working by calling a function that removes the event listeners before drawing the screen on top but i guess this is not very efficient (but then again on selecting a button the screen generally need redrawing anyway - the redraw adds the event listeners for whatever buttons are on that page etc) [import]uid: 5872 topic_id: 1066 reply_id: 3118[/import]