A very subtle but important change needs to be made:
local square = display.newRect( 0, 0, 100, 100 )
local function RemoveObject( target )
target:removeSelf()
target = nil
end
local function Trans()
transition.to ( square, {time = 2000, x = 200, y = 200, onComplete = RemoveObjec t} )
end
square:addEventListener(“tap”, Trans)
When you have onComplete = someFunction( ) with the parens attached, you are calling that function and taking the value returned by it and assigning it to onComplete. As your code is originally written, it calls RemoveObject() which removes the object and since your function doesn’t return anything, it assigns a nil to onComplete.
The version I posed above, RemoveObject the function isn’t called, but instead the address of RemoveObject is assigned to onComplete for when the transition finishes, it has a function to run at that time.