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

What is Framer? Join the Community
Return to index
Andy Cetnarskyj
Posted Oct 13 - Read on Facebook

Newbie question, Is there a way to loop these layers in a function instead of doing it manually?
panel1 = new Layer
backgroundColor: "#cc9900"
x:0, y:0, width:260, height:768
panel2 = new Layer
backgroundColor: "#ffcc00"
x:260, y:0, width:260, height:768
panel3 = new Layer
backgroundColor: "#cc4400"
x:520, y:0, width:260, height:768
panel1.superLayer = panelContainer
panel2.superLayer = panelContainer
panel3.superLayer = panelContainer


Seoh Char

panelContainer.subLayers.forEach (panel)->
panel.backgroundColor = Utils.randomColor()

did you find a way like this?

Mike Meyer

If you don’t need to three explicit variables named panel1, panel2, and panel3, you can build an array of numbers and then create a new Layer for each number in a loop. Coffeescript makes it a bit weirder. I’d recommend perusing the CoffeeScript docs on loops:

Andy Cetnarskyj


Mike Meyer

Andrew sure thing.

Read the entire post on Facebook