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

What is Framer? Join the Community
Return to index
Joseph Van Geffen
Posted Jul 15 - Read on Facebook

Howdy Framer JS'rs! I'm having issues keeping my Framer.js/Coffeescript code DRY. Any good tutorials out there? (To be specific, I have a dynamically generated list of buttons with event listeners (for swipe/touch/etc). I ended up copy pasting the events over and over instead of being able to programmatic-ally create/set them).

13 Comments

Rohan K

+1 ..ive got the same issue ... 10 layers with 4 identical events on each, but i have to copy/paste them over and over again for each layer

Chris Camargo

Use loops?

Jordan Robert Dobson

Yep. Use loops or functions to do that work.

Joseph Van Geffen

Sure, but what is the correct syntax for dynamic instantiation? item+x = new Layer x:0, y:0, width:100, height:100 - item+x doesn't work.

Jordan Robert Dobson

Ah... You just want to create layers and don't care about the name?

You can skip assigning it to a variable altogether. Or you can assign it to an object.

myLayers = {}

for id in [1..10]
myLayers["layer#{id}"] = new Layer x:0, y:0, ... continue setting properties

Joseph Van Geffen

Thank you! I believe this is what I was looking for.

Jordan Robert Dobson

No problem!

Joseph Van Geffen

So this was very useful for creating items with unique names and applied handlers. But I cant seem to discretely select them beyond using this inside the handler. Specifically, inside that layer I created a sublayer with html text. I've tried this.subLayers[index+1].html and layername+#{id}.html etc...

Jordan Robert Dobson

print this.subLayers

Jordan Robert Dobson

What do you get?

Joseph Van Geffen

Ahah! this.subLayers[1].html

Joseph Van Geffen

thank you again

Jordan Robert Dobson

:D

Read the entire post on Facebook