How to destroy a timeline?

After setting an onComplete callback for a certain timeline, both stop and destroy timeline's methods cause the onComplete callback to be called.

How can I avoid such a behaviour?

Should I manually remove the callback first, or there is a quicker way to achieve that?

I guess you have to remove them.

timeline.callbacks.onComplete = null;
1 Like

Yeah, I guess so.

At the end I have created a method:

	cancelTimeline(timeline) {
		if (!timeline) return;

		Object.keys(timeline.callbacks).forEach((key) => {
			timeline.callbacks[key] = null;
		});
		timeline.destroy();
	}

It would be nice to have a cancel method on the timeline class itself.

Thanks Samme

It looks like you can do

timeline.destroy();

this.tweens.remove(timeline);

to avoid the onComplete callback.

1 Like

Thanks for that Samme. However I think it is best to stick with the “hardcore” solution, it appears to be more robust towards future framework updates.

Pretty sure remove() will keep working.