Hi!Could someone explain me how I could apply layer.animate to all layers stored in the array instead of the last one? Thanks!
Hello Hugo des Gayets you can use @animate instead of layer.animate as "@" will contain the appropiate layer every time the click is fired. You can see an example of what I mean here: http://share.framerjs.com/c2xtp5i9elqy/
adding '(event,layer)' to the part of your code where you set up the event should also work, like here: http://share.framerjs.com/99e3kr43oe9i/
Thanks Adria Jimenez I'll try this!
Thanks Ben Rodenhäuser!
Basically by the time you click layer is equal to the last element in the loop because there aren't any more to set layer to. So you have to use "this" as in this.layer or @.layer.
This refers to the element clicked that calls that function.
Thanks Jordan Robert Dobson!
1. You can get rid of the allLayers.push(layer) by adding every layer to the array at their creation:
'layer = allLayers[i] = new Layer'
2. You can also git rid of the second loop (just remove line 26)! Instead of animating layer ('layer.animate') on Click, use '@.animate' or 'this.animate'.
Two examples:1. http://share.framerjs.com/3woxywmi8t5o/... here I'm using states instead of animation, but its the same logic
2. http://share.framerjs.com/peglr4t5j3q8/... contains an in-depth description of how for-loops work in conjuncture with arrays :)
Or you can make use of closures, which is probably the least preferable solution but it works as well:http://share.framerjs.com/esc5j05yriq6/