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

What is Framer? Join the Community
Return to index
John Grendon Enderby
Posted Jan 30 - Read on Facebook

Hi Folks! Maybe a bit of a basic question for some of you and my guess is that it has something to do with scoping but why can't I access a layer created in a for loop by name, but pushing them to an array allows me to access the layer with [] notation, and I can pull the name from the array using products[0].name? I have attached an image to illustrate if my explanation is not good enough ;)

5 Comments

Fran Pérez

"Name" is just a another property of layer. In order to use the object you've just created, it has to be assigned to a variable, which in your case is the array: products. You refer to an array element by referring to the index number using [].

Jordan Robert Dobson

You'd have to do product1 = new Layer .... If you wanted to use it that way.

Ben Rodenhäuser

For me, this was initially confusing: If I can't access layers simply "by name", why can I access my Sketch layers by the name shown in the layer inspector? The answer is that Framer creates a variable for each Sketch layer on import.

Michael Neal

products[1] que no

Nathan Krischer

The error states why. You have no variable product1 declared. You created the array products and pushed the layers to it. You did not in the image anywhere ever declare product1.

Read the entire post on Facebook