Remove an object from a transition and tap

When The transition is finished, the box is removed. it works fine.

the problem is when I tap the object,

the object is removed and then I get this log

main.lua:12attemp to index global ‘object’(a nil value)

stack traceback:

main.lua:12 in function<main.lua:9>

    (tail call):?

    ?:in function<?:481>

    ?:in function<?:481>

    end

end

if Ï tap the object how can I cancel the remove function of the transition

[lua]local physics = require( “physics” )
physics.start()
physics.setScale( 40 )
physics.setGravity( 0, 0 )

local function removeBox(event)

object:removeSelf()
object = nil
print(“object remove”)
end

object = display.newImageRect(“box.png”,40,40)
physics.addBody(object, “dynamic”, {density = 0, friction = 0, bounce = 0});
object.isSensor = true
object.x = 80
object.y = 260

transition.to ( object, { time = 3000, x = 80, y =60,onComplete=removeBox} )

local function onObjectTap( event )
print( “Tap object” )
object:removeSelf()
object = nil

end
object:addEventListener( “tap”, onObjectTap )[/lua]

use

display.remove(object)

instead.

use

display.remove(object)

instead.