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

What is Framer? Join the Community
Return to index
Artemy Zemlyanika
Posted Nov 23 - Read on Facebook

Hi every1!

I'm having trouble to refer to a layer created by a "for loop". What am i doing wrong here?

7 Comments

Jung Sun Yoo

proof_arr =[]
for i in [0..9]
layer = new Layer
.... (properties) ......
proof_arr.push layer
proof_arr[1].width = 104

Philip Illum Thonbo

get layer by name ? if you can then try proof.proof1.width or make a function that can return a layer by its name

Gregory J. Orton

This was a question from last year too. One of the best ways to do it is to attach them to the window object, then you can give them a name programatically, and access them in the global context in framer by name:

for i in [0..9]
window["poof#{i}"] = new Layer
name: "poof#{i}"
...
...
image: "images/smoke#{i}.png"

poof1.width = 0
poof2.opacity = 1
...
....

Chris Camargo

Artemy Zemlyanika, I answered this same question recently: https://www.facebook.com/groups/framerjs/permalink/937689979691407/

Jordan Robert Dobson

Yeah name isn't the same thing as variable name.

Basically you gave them all the same variable name of "layer" and then just reassigned it.

Name is mostly for your reference although there are a few tools that help you search by name. But it's not something I'd rely on.

Brian Williams

Learn about scope

Brian Williams

Oh wait are you just setting the name and hoping that will work? You could do the selection based on the name but the best solution is either to store it in an array and reference it via its index or to store it in what is the equivalent of a dictionary/ keyed array in js, I.e an object literal.

You can then just use the myobject['myproperty']

Syntax to reference it

Read the entire post on Facebook