如何为在 framerJS 中的 for 循环内创建的图层设置不同的名称

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

我喜欢为在 for 循环中创建的图层设置不同的图层名称。以下是有效的代码,但它创建了三个名为 "circle" 的层,这使我无法做任何特定于第二个圆

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

我试过做 circle[i] 但没成功。非常感谢任何帮助。

您需要创建层数组:

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

或更多 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

并访问:

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