metalslug87 Posted December 15, 2016 Share Posted December 15, 2016 Hello, I've problem with animation complete callback, when fired first time it's ok. On next function executions it's adding additional console.log value "nut fired". So the JS console output looks like that (it's adding additional execution of animation callback): nut fired! -> nut fired! (3) -> nut fired! (6) -> nut fired! (10) ... function squirellThrowNut () { for (var i = 0; i < squirells.length; i++) { squirells.children[i].animations.play('throw'); squirells.children[i].animations.currentAnim.onComplete.add(function () { for (var i = 0; i < squirells.length; i++) { console.log('nut fired!'); } }, this); }; } Please help me, I can't figure it out. Link to comment Share on other sites More sharing options...
drhayes Posted December 15, 2016 Share Posted December 15, 2016 What are you trying to do? I mean, why is that loop inside the onComplete listener? Are you changing the number of squirrels dynamically? Maybe you meant "addOnce"? samme 1 Link to comment Share on other sites More sharing options...
XekeDeath Posted December 15, 2016 Share Posted December 15, 2016 You are adding new callbacks each time squirrelThrowNut is called, and the old ones are still there... addOnce, as drhayes suggests will fix this for you, as the callback is removed when it is called. Link to comment Share on other sites More sharing options...
metalslug87 Posted December 16, 2016 Author Share Posted December 16, 2016 Yes! addOnce worked like a charm! Thank you very much ! Link to comment Share on other sites More sharing options...
Recommended Posts