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

What is Framer? Join the Community
Return to index
Tom Lakovic
Posted Jun 25 - Read on Facebook

Help >> I have an array of button names and dynamically setting the handlers for each in a loop. But when those buttons are clicked at run time, they *all* call the function with the same parameter, not the loop index as i expected, but the last loop index. Stumped. (guessing: something to do with a pointer? how do i dereference it if so??) thx.

# note: item1_Btn to item4_Btn are targeted layers in "design"
# (ie. they are buttons)

subNav= ["item1","item2","item3","item4"]
for i in subNav
eval(i+"_Btn").onClick ->
select(i)
#
#
select = (x) ->
print x
# all buttons print "item4" when pressed ... wtf?

1 Comments

Jonas Treub

Check out the scope section of our programming primer: https://framer.com/getstarted/programming/

Read the entire post on Facebook