Page 1 of 1

[SOLVED] Javascript: waiting for animation to finish

Posted: 12 April 2020, 18:38
by apollo1001
Hi,

I've chained some animations together and am wondering how I can get the normal javascript code to wait for their completion before continuing. At the moment the calls after 'play()' are firing whilst the animation is in progress.

I'm clearly missing something simple, so any advice appreciated!

Adam

Code: Select all

var combined_anim = dojo.fx.chain(potion_ready_anims);
dojo.connect(combined_anim, 'onEnd', function(node) { 
    // Ideally need to have this onEnd method trigger the final few methods 
    dojo.destroy('potion_' + potion_id); });
combined_anim.play();

// These need to run after the animation has completed or somehow be inserted into the chain at the correct point
this.updateDispenser(tube1, tube2, tube3, tube4, tube5);  
this.cupboards[player_id].addToStockWithId(potion_type, potion_id, 'potion_' + potion_id);

Re: Javascript: waiting for animation to finish

Posted: 12 April 2020, 18:53
by DrKarotte
The disc animation chain in the Reversi tutorial has the onEnd function as part of the chain, perhaps this makes a difference? I am not an expert on this, quite the opposite.

Re: Javascript: waiting for animation to finish

Posted: 13 April 2020, 16:55
by Tanguy_D
I had an issue like you, and solved my problem like this :

Code: Select all

combined_anim.onEnd = function() {
// Your code
};
We should add 'onEnd' on each animation object on a combined / chain, but dojo does not handle it very well.

Re: Javascript: waiting for animation to finish

Posted: 15 April 2020, 09:06
by apollo1001
Thank you for the replies. I have now found the solution:

Code: Select all

dojo.connect(animation_id, 'onEnd', dojo.hitch(this, 'callback_function', parameters));