removeSelf on a nil object?

I have the following function:

function fadeRect(event) transition.to(event.target, {time=2000, alpha=0.5, onComplete= function() if event.target then event.target:removeSelf() end end }) end

Which I have as the touch handler of a rectangle.  When I touch the rectangle, the fade works but when it tries to call removeSelf(), I get an error about trying to call removeSelf on a nil value.  However, it obvious that event.target exists because otherwise the call to removeSelf would be skipped.

Any ideas?

Try removing if statement and change
event.target:removeSelf()
To
display.remove(event.target)

Thanks!  That did the trick.  What is the difference between removeSelf and display.remove?

the same as calling object:removeSelf(), but will first check if the object exists before attempting to remove.

Try removing if statement and change
event.target:removeSelf()
To
display.remove(event.target)

Thanks!  That did the trick.  What is the difference between removeSelf and display.remove?

the same as calling object:removeSelf(), but will first check if the object exists before attempting to remove.