In my game, I create items, add them to a displayGroup then add tap eventListeners to them. When an item is clicked, I remove the listeners for the duration of my code loop, then add them back in (basically disable touches to any objects while I am executing code).
Everything works until I try to add the eventListeners back in. It crashes the simulator and an actual device. I am using v.268
[code]
–I’ve removed unnecessary code
local DGroup = display.newGroup()
–Method that gets called from eventListener
local removeBox = function( event )
local originalBoxPassedIn = event.target
findBoxesToRemove(originalBoxPassedIn)
end
–Initial setup of boxes on screen (70 boxes created)
boxesMatrix = {}
for i=1,10 do
boxesMatrix[i] = {}
for j=1,7 do
boxesMatrix[i][j] = {}
DisplayNum = DisplayNum + 1
boxesMatrix[i][j].image = display.newImage( “buttonImage”…choice…“s.png” )
boxesMatrix[i][j].image.myIndex = DisplayNum
DGroup:insert( boxesMatrix[i][j].image )
DGroup[DisplayNum]:addEventListener( “tap”, removeBox )
end
end
function findBoxesToRemove(originalBoxPassedIn)
–This code works, it makes all the boxes non-clickable
for x=1,DGroup.numChildren do
DGroup[x]:removeEventListener( “tap”, removeBox )
end
–Here is my long code loop
–…
–After the loop, try to add all the listeners back in
for y=1,DGroup.numChildren do
DGroup[y]:addEventListener( “tap”, removeBox )
–Calling this causes the simulator to crash
end
end
[/code] [import]uid: 28218 topic_id: 6501 reply_id: 306501[/import]
