I'm looking to create a few layers through a for loop, animate each one, and then destroy it but only one layer is being deleted. Anyone have an idea of how to do it?
Here's my code:
for num in [0..10] layer = new Layer
animation = layer.animate properties: y: 1000 delay: num
animation.on "end", -> layer.destroy()
Here's a working version: http://share.framerjs.com/433ry7a8sxhn/
The way you have it, every time it goes through the loop, "layer" is getting redefined to the new layer that gets created. So by the end, all of the events are trying to destroy the last layer.
To learn more about weird things happening to variables when you're setting up events in loops, read about lexical scoping and closures. It can be a bit confusing at first, but you'll get so much benefit from understanding what's going on.