I’m animating a set of layers in an array and I want to do something when all the layers have finished animating. What’s the best way of doing this?
Say you had 5 layers in the array. couldn't you do array.onAnimationEnd -> ?
In addition to Aalok Trivedi's suggestion, if you can't be sure that the last layer in the array will finish last, you can just set a counter that gets 1 deducted on every layer's onAnimationEnd. And every time you deduct 1 you also check if the counter is now 0. If it is, do stuff :)
One possible solution is proposed by Aalok ›array[array.length-1]‹ gives you the last array item dynamically (without hardcoding the number).
Second possible one is to calculate collective duration of all animations and then delay certain behavior:
delayLength = array.length*durationUtils.delay delayLength, ->
Another one: if you are generating your layers in a for loop, let's say:you create a layer called ›menuItem‹ and then add to array, you can use menuItem.onAnimationEnd inside for loop as it will target the last item created in a loop :)
etc... I guess there's no "best way"
Thanks for all of the replies. Really helpful!