consider this example,
local object = display.newImage( "ball.png" )
function object:touch( event )
if event.phase == "began" then
display.getCurrentStage():setFocus( self )
self.isFocus = true
elseif event.phase == "moved" then
print( "moved phase" )
elseif event.phase == "ended" or event.phase == "cancelled" then
display.getCurrentStage():setFocus( nil )
self.isFocus = false
end
end
return true
end
object:addEventListener( "touch", object )
If you doesn't add the phase your touch will be detected in all the three phase,
thus it executes all the statements with in function three times.
To avoid this we are using the phase.
In your case ,
local onCollision = function(event)
event.object2:removeSelf();
event.object2 = nil;
end
Runtime:addEventListener("collision",onCollision);
The code inside this will be called three times, this results in error. Since in began phase itself your object will be removed, when it comes to moved phase it will give you error, since object is already removed.
Please refer this, http://docs.coronalabs.com/api/event/touch/phase.html