How to cancel transition.blink after a particular time?

Hello everyone,

I am creating a rectangle which should blink for 5 secs and then it should be removed.First to cancel the blinking process after 5 secs I am using timer.performWithDelay() and then as the transition gets cancel I have used onCancel to call a function which removes rectangle.

The problem is transition.cancel() is not getting applied after 5 secs but its getting applied as the program runs.

Following is the code:

local rec1=display.newRect(0,0,display.viewableContentWidth+200,display.viewableContentHeight+200 ) rec1.name="rect1" rec1.anchorX=0 rec1.anchorY=0 function canceltrans(a) transition.cancel(a) end function removerec() rec1:removeSelf( ) end a=transition.blink( rec1, {time=1500, onCancel=removerec() } ) timer.performWithDelay( 5000, canceltrans(a) )

I am not understanding what is going wrong, please see if someone can help.

Thanks and Regards,

Swanand Thakur

Hi,

you can reference transitions by the objects, so not really neccessary to assign it to a variable.

perhaps that is why it doesnt work.

Something like this:

local rec1=display.newRect(0,0,display.viewableContentWidth+200,display.viewableContentHeight+200 ) rec1.name="rect1" rec1.anchorX=0 rec1.anchorY=0 transition.blink(rec1,{time=1500}) timer.performWithDelay(5000,function() transition.cancel(rec1) end)

Sir @anaqim,

Thanks alot for your input. The solution given by you has solved my problem.

In the last line in timer.performWithDelay there sould be “rec1” and not “rect1” just making notify because if anyone else is refering the same then it will create an error.

Thanks and regards,

Swanand Thakur.

misspelling corrected  :slight_smile:

Hi,

you can reference transitions by the objects, so not really neccessary to assign it to a variable.

perhaps that is why it doesnt work.

Something like this:

local rec1=display.newRect(0,0,display.viewableContentWidth+200,display.viewableContentHeight+200 ) rec1.name="rect1" rec1.anchorX=0 rec1.anchorY=0 transition.blink(rec1,{time=1500}) timer.performWithDelay(5000,function() transition.cancel(rec1) end)

Sir @anaqim,

Thanks alot for your input. The solution given by you has solved my problem.

In the last line in timer.performWithDelay there sould be “rec1” and not “rect1” just making notify because if anyone else is refering the same then it will create an error.

Thanks and regards,

Swanand Thakur.

misspelling corrected  :slight_smile: