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

What is Framer? Join the Community
Return to index
March Rogers
Posted Mar 05 - Read on Facebook

I'm trying to turn on an event listener for a layer created in a for loop. In the loop I assigned unique names for each layer and those names appear correctly in the layer tree view panel. However Framer Studio doesn't appear to be aware of the unique names (it only shows the original new layer name in the auto-complete drop down) and so I can only add an event listener to the last of the created layers. Any help? Thanks!


Juan J. Ramirez

How are you creating those unique names?

March Rogers

for index in [1...5]
notebook = new Layer
name: "notebook" + index

Markus Smet

Here's a few suggestions:
- What about adding the Event listener inside the 'for index in[1..5]' loop and apply it to each new Layer?
- Put the Layers from the for loop into an array, and iterate through that with 'for nb in noteBook[i]' to apply the Event listener to each Layer in the array. I think this will overwrite the Layers in the interface with an updated version of your notebook Layer.
- Try using this module

March Rogers

Thanks for the reply Markus. I must not be understanding what you're suggesting. I tried the first and second suggestion but got errors. I don't understand how to use the module to solve my problem. If it's useful here's a link to my prototype (currently a wireframe while I work out the interaction).

Jordan Robert Dobson

Yeah the name is only a way to easily identify it. It's merely a property like width is a property... There are utilities out there to find them by name however.

Jordan Robert Dobson

So here's what I'd recommend.

Before you loop create an array to store all your notebooks.

notebooks = []

Then in your for loop

for index in [1...5]
n = notebooks[index] = new Layer ...

Read the entire post on Facebook