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

What is Framer? Join the Community
Return to index
夏洛克
Posted Sep 10 - Read on Facebook

Hey everyone,I got a problem with new version Framer...
I try to setting something or binding event in layer's sublayers use for-loop,but something wrong...It will always run the last element in for-loop.Is it a bug ? or I miss something? Thanks~^^

my share project :
http://share.framerjs.com/y71uz1facv5n/

code is very simple:

LayerStack=new Layer
.height:100
.width: Screen.width

layer1=new Layer
.width: 100
.height: 100
.backgroundColor: Utils.randomColor()
.parent: LayerStack
.name:"L1"

layer2=new Layer
.width: 100
.height: 100
.x:100
.backgroundColor: Utils.randomColor()
.parent: LayerStack
.name:"L2"

for item in LayerStack.subLayers
.item.on Events.Click,->
..print item.name

2 Comments

Niels van Hoorn

You ran into a classic example of misunderstanding scope ;)
You can read up on it here: https://framerjs.com/getstarted/programming/#scope

Your current problem can be most easily fixed by using 'this' or its synonym '@' instead of item:
item.onClick ->
. print @name

夏洛克

Thanks very much, Niels. ^^

Read the entire post on Facebook