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

Movieclip autoReset causes frame actions to be executed in reverse order when movieclip is reset #114

Open uhalliwell opened 1 year ago

uhalliwell commented 1 year ago

Under CreateJS 1.0.0, when a multiframe movieclip is present on the stage (with autoReset in the default TRUE state), then removed, then added again, the reset behavior causes all the movieclip's frame actions to be executed in reverse order from its current frame, which is clearly not desirable, and was not the default behavior under CJS 2015.

Note that I'm working in the Adobe Animate environment, but based on my investigation this seems to be an issue with TweenJS instead of anything Adobe's layered on top of it.

For example, say you have a five-frame movieclip, with an action on frame 1 of "console.log(1);", then "console.log(2);" on the next frame, etc., with an added "this.stop();" on the last frame. Then place this movieclip on a root timeline with enough frames for the movieclip to fully play, and a blank keyframe at the end so the movieclip will be removed from and re-added to the stage when the root timeline loops. What you'll see in the console is: 1, 2, 3, 4, 5, 4, 3, 2, 1... repeating. The 4, 3, 2, 1, spews all at once within a single tick.

In AbstractTween.js, p._runActions(), around line 533, I added this line of code after "if (jump)...": else if (t0 > t1 && !this.reversed) { return this._runActionsRange(t1, t1, jump, true); }

This seems to fix the problem, though TweenJS has to handle so many edge cases I doubt this is a proper fix. I'd imagine having the reset() method set a flag would be preferable.

Details: Adobe Animate 23 (Build 103), Windows 11, all browsers