0

I can't figure out how to change the name of a layer I've created. Not the layer.name property, but the actual name of the layer.

For example, I would like this to print out 40:

test = new Layer ({
    height:40,width:40
})

//replace "test" with "foo," somehow

console.log(foo.height)

test.name="foo" doesn't work as the commented line. If this name-changing can't be done in framer, is there a particular reason I'm missing that the feature doesn't exist?

Traviskorte
  • 113
  • 8
  • Equivalently, it would be useful to name a layer after the contents of a variable. Like: var newName = "foo" newName = new Layer ({ height:40,width:40 }) console.log(foo.height) This also does not work. The layer gets named "newName" without noticing that it's a variable that's already been declared. – Traviskorte Feb 12 '15 at 22:40

2 Answers2

0

You can choose any name you want for your variable:

foo = new Layer ({
    height:40,
    width:40
})
console.log(foo.height)

If you already have a variable with a layer, you can store it in a different one:

var test2=test;
Peanut
  • 3,753
  • 3
  • 31
  • 45
-1

test is just the name of the variable used to store the layer. You can store that object in another variable just like ordinary javascript:

var foo, test;

test = new Layer ({
  height:40,
  width:40
});

foo = test;

console.log(foo.height)

Update A common use of this in framer is when importing from Sketch or Photoshop. Then you map all the imported layers to new variables to make it easier to rename and re-import. Like this:

Imports = Framer.Importer.load "imported/My Sketch File"

TradeView = {}

TradeView.Window = Imports.Trade_View
TradeView.closeBtn = Imports.Close
TradeView.Buy = Imports.Input_buy
TradeView.Sell = Imports.Input_sell

TradeView.sellDrop = Imports.Sell_dropdown
TradeView.buyDrop = Imports.Buy_dropdown
TradeView.calendarDrop = Imports.Calendar
  • 1
    why use two variables? – Peanut Apr 22 '15 at 09:29
  • No good reason except that the OP specifically wanted to change the name of the variable used for undisclosed reasons. I assumed that if he could have used another variable name to begin with, he would have done that. – Jesper Wøldiche Apr 22 '15 at 12:22
  • I should have been more clear: I'm only trying to change the name of the existing layer, not duplicate the layer under a new name. If this is fundamentally not possible in framer, that's also a satisfactory answer. – Traviskorte Apr 28 '15 at 00:57
  • In the example above the layer is not duplicated. There is still only one layer. But the layer is now stored in two variables - both test and foo. So: test.on(Events.Click, function() { ... }); is identical to foo.on(Events.Click, function() { ... }); – Jesper Wøldiche Apr 29 '15 at 13:43
  • I have updated my answer above to include a framer.js specific usecase. – Jesper Wøldiche Apr 29 '15 at 13:50