coffeescriptframerjs

How to set different name for layers that are created inside for loop in framerJS


I like to set different layer name for layers that are created inside the for loop. Following is the code that is working, but it creates three layers named "circle" which prevents me from doing anything specific to let's say the second circle

for i in [1..3]
    circle =  new Layer
        x: 15 + i*50
        y: 15
        height:10
        width:10

I tried doing circle[i] but it didn't work. Any help is highly appreciated.


Solution

  • You need to create array of layers:

    circles = []
    for i in [1..3]
        circles.push new Layer
            x: 15 + i*50
            y: 15
            height: 10
            width: 10
    

    or more coffeescript'ish (thx @moo_is_too_short)

    circles = for i in [1..3]
        new Layer
            x: 15 + i*50
            y: 15
            height: 10
            width: 10
    

    And access:

    circles[0]
    circles[1]
    circles[2]