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]