Remove object on touch.move event

Hi there!, I’m not getting this, I have a displayGroup to wrap other four displaygroups with a square in a row something like this:


[1] [2] [3] [4]

So if I drag the group 1 to collision with the object 4 I want it to be removed.

The weird thing is that although I can see the displayObject being removed, the touch.move event is still being triggered and so the next round for the move event it fails.

I’ve put a print statement in order to see if the taget:removeself works but after removing I can still access to the x property of the removed display group, wich it’s really confusing.

Am I missing something here or there’s any fancy thing to do in order to remove objects in this touch stage?

[code]

local function objectTouchHandler(event)
local target = event.target

if event.phase == “began” then

display.getCurrentStage():setFocus( target )
target.isFocus = true

target.xScale = 1.1
target.yScale = 1.1
target.alpha = 0.5
target.markX = target.x

elseif event.phase == “moved” then

target.x = ( event.x - event.xStart) + target.markX

if hasCollided(target.boundsToCheck, objects[4]) then
print(“Colision”)
target:removeEventListener(“touch”,objectTouchHandler);
target:removeSelf()
print(target.x) – Here it still prints target’s x, I would expect an error because of the previous removal
target = nil

for i = 1, #objects do
print(objects[i])
end

end

elseif event.phase == “ended” or event.phase == “cancelled” then
target.xScale = 1
target.yScale = 1
target.x = 0
target.alpha = 1

display.getCurrentStage():setFocus( nil )
target.isFocus = false
end
return true
end

local maxObjs = 4
local grupoObjs = display.newGroup( ) – main displaygrup to contain objects displayGroup
grupoObjs.x = 0
grupoObjs.y = 100

for i = 1, maxObjs do
local xPos = ( ( _W - 65 ) / maxObjs ) * i – To separate the objects
local object = display.newGroup() – Group to be dragged
local o = display.newRect(object, 0, 0, 50, 50 ) – square visible inside the objects displayGroup
o.x = xPos
o.y = 0

grupoObjs:insert(object)
object:addEventListener( “touch”, objectTouchHandler )

table.insert(objects, object)
end
[/code] [import]uid: 8933 topic_id: 26359 reply_id: 326359[/import]