tween.js icon indicating copy to clipboard operation
tween.js copied to clipboard

'Cannot read property 'update' of undefined'' error on calling twen.stop()

Open khurramraheel opened this issue 12 years ago • 5 comments

It seems that if we call twen.stop() within the tween's onUpdate function, it throws the following error:

'Cannot read property 'update' of undefined''.

khurramraheel avatar Oct 28 '14 10:10 khurramraheel

the tween.stop() method cannot be called within another internal method.

thednp avatar Oct 28 '14 13:10 thednp

Well, that could be a problem, what if we want to check a condition in the update method and want to terminate the tween based on that condition.

khurramraheel avatar Oct 29 '14 04:10 khurramraheel

I have had a similar issue with calling tween.stop() method inside the onComplete() method of a different tween. I think it should be possible to stop a tween B when a tween A completes, don't you think that would be good? In this situation there is no error, but depending on the situation (i.e. number of tweens being stopped in the onComplete callback) then my onComplete method gets called twice SOMETIMES. Otherwise it works. I was able to fix my issue by not attemping to stop any tweens in the onComplete callback and in my situation I was able to get away with this but it seems that it would be important to be able to do so, generally speaking, no?

dnassler avatar Nov 03 '14 20:11 dnassler

I am a bit confused about your suggestion, I guess onComplete fires once the tween is completed and hopefully it internally calls stop(). so calling stop() inside the onComplete does'nt make much sense. As far as my problem is concerned, I have a single tween that I want to stop before it gets completed.

khurramraheel avatar Nov 04 '14 05:11 khurramraheel

I was just saying that I see issues with calling stop on any OTHER Tweens during the onComplete call. This is intermittent.

But as far as suggestions for working around the problems yours and mine... How about trying to invoke a window.setTimeout in your onUpdate in the rare special case in which you need to stop the tween... And have the timeout be zero. I think that would avoid calling the tween logic from the tween callback directly but still get your job done.

Sent from my iPhone

On Nov 4, 2014, at 12:57 AM, khurramraheel [email protected] wrote:

I am a bit confused about your suggestion, I guess onComplete fires once the tween is completed and hopefully it internally calls stop(). so calling stop() inside the onComplete does'nt make much sense. As far as my problem is concerned, I have a single tween that I want to stop before it gets completed.

— Reply to this email directly or view it on GitHub.

dnassler avatar Nov 04 '14 23:11 dnassler