This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Diego Oriani
Posted Oct 19 - Read on Facebook

Help! I am struggling to create a loop inside of a loop. Only the last 'square' is triggering the event. How can I assign the event to each 'square'?

Thank you in advance.

array = ["01","02","03", "04"]

for squares in array

layer = new Layer
y: 102 * squares
backgroundColor: "white"

for each in array
layer.on Events.Click, ->
layer.backgroundColor = "Red"

8 Comments

Anton Jarl

Could you share? Otherwire, try to do "for each in arraySuperLayer.subLayers"

Diego Oriani
Jonas Treub

layer is overridden during each assignment. Inside the event scope you can refer to self to get the right layer. Shorthand for self is the @ symbol. http://share.framerjs.com/m07xs4cpoo7m/

Diego Oriani

Jonas Treub What about if the hit area is a different layer? Let's say I need to click in a different layer to toggle between states on another element. By the way, thank you for the help so far.

Diego Oriani
Jonas Treub

Than the variable holding that layer needs to be unique. You could also store the linked layer as a property on the interactive layer like so: http://share.framerjs.com/kib9jyz9niad/

Andrew Nalband

Diego - you could also give your layers a name property and append a unique number in the for loop.

Diego Oriani

Jonas Treub This is interesting. What else can be stored as a property? Is there any documentation for that? Thank you Jonas.

Read the entire post on Facebook