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

What is Framer? Join the Community
Return to index
Daniel Keller
Posted Dec 12 - Read on Facebook

Hello Guys,

I have another a very basic programming issue:

I have a loop that creates some layers, and gives each layer a unique name. Now I want to have on each unique layer a drag event and for each layer unique dragging coordinates should be used.

For this I have to use i in the variable names, but I have no idea how to do that, my example on the bottom obv does not work, but I guess it shows what I want to achieve.

Basically I need aY0 aY1 aY2 aY3 ... aY10
and also layer1 layer 2 layer 3 ... layer10

Thanks already :)


Jonas Treub

Can you explain the effect you are trying to achieve? (Without explaining the current code)

Daniel Keller

I have those 11 Layers, each are draggable. When each of those layers is dragged the y position of those are stored into a variable. Those variable are used to draw an svg graph (example in the screenshot) the white dots are the layers.

Jonas Treub

Here is a quick example how you can get all the points when you drag them: Let me know if you want me to clarify certain parts of the code.

Daniel Keller

Okay I think I understand what you did there, and its exactly what I need, right know you print an array with all the Y values? How would I access for example the Y value from layer 3?

Daniel Keller

Okay I think I got it :) BIG THX!

Daniel Keller

Jonas Treub Hey I encountered a problem with your code! The array looks like that: » [{y:360}, {y:388}, {y:360}, {y:360}, {y:360}, {y:360}, {y:360}, {y:360}, {y:360}, {y:360}]

How can I make it that I just have the raw integers in the array?

So that it looks like that:

[360, 388, 360, 360, 360, 360, 360, 360, 360, 360]

Jonas Treub

You can do that by returning the number from the map function instead of the object.

Daniel Keller

I tried:

updateSVG = ->
points = =>
return {layer.y}

but that marks the line red for me without any error :/

Jonas Treub

You can return layer.y without curly braces. That should do it

Daniel Keller

Perfect thanks, so the curly braces are objects right?

Jonas Treub

Yeah! It's a shorthand for creating objects

Read the entire post on Facebook