CreateJS / TweenJS

A simple but powerful tweening / animation library for Javascript. Part of the CreateJS suite of libraries.
http://createjs.com/
MIT License
3.56k stars 967 forks source link

Tween not firing when canvas is replaced #33

Closed KokoDoko closed 10 years ago

KokoDoko commented 10 years ago

I am adding and removing a html canvas element in an ajax application. When a new canvas is removed and added, I set the CreateJS stage to the new canvas.

So far it works, but my Tween is not firing any more. When adding an onchange handler to the tween, that doesn't fire either.

I can't figure out if the tween is broken, or is the tween still rendering to the old canvas? I have created a fiddle here:

http://jsfiddle.net/BUyyv/2/

lannymcnie commented 10 years ago

The problem is that Tween adds a single listener to the Ticker when it is initialized, which is wiped out when you removeAllEventListeners.

As a workaround, you can add a listener back in using:

createjs.Ticker.addEventListener("tick", createjs.Tween);

Note that you should ensure you don't do this multiple times, as it could stack up multiple callbacks. http://jsfiddle.net/lannymcnie/BUyyv/4/

KokoDoko commented 10 years ago

Thanks for checking it out!