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

What is Framer? Join the Community
Return to index
Dmitry Sholkov
Posted Jan 29 - Read on Facebook

Hey all!
I’m trying to figure out how to pass an Arrayindex from the layer inside that array?

So imagine there is 10 layers in array and I have a for loop for them.

for i in [0…10]
ArrayA[i].on Events.MouseOver, ->
print this.array.index

The reason I want this so I could have multiple arrays, and having MouseOver one layer, it triggers a bunch a layers from different arrays with the same array index each.

2 Comments

Koen Bok

No, this is a common error in JS because of scoping. JS scopes variables by function so the mouseover function you define always gets the last loop i variable. You can learn more here: http://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript

To fix it, you can do a few things. I always like to use the map function, but a pro trick is to use do:

Ben Rodenhäuser

I tried this out too, but I think I fail to understand it. This example works (layers in second row move based on mouseover on first layers in first row): http://share.framerjs.com/o77rv447emwy/ But if I don't instantiate the layers in the scope of "do" but upfront it won't work anymore. Now why is that? Probably that's kind of the point of using "do", but leaves me clueless.

Read the entire post on Facebook