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

What is Framer? Join the Community
Return to index
David Caputo
Posted Apr 23 - Read on Facebook

I'm trying to do a check that says: If this layer exists: Destroy it. But I can't figure out how to check if a layer exists. Feels like I may be going about this the wrong way but just curious if there is a simple way to do this that I'm overlooking.


Chris Camargo

I usually look for something to key off of... Is the layer you're seeking a subLayer of another layer? If so, you can check for it using `if parentLayer.subLayersByName("layerName")`.

Chris Camargo

Or, in other words...

David Caputo

Ah that's perfect! Thanks!

Chris Camargo

Keep in mind that subLayersByName actually returns an array of layers. So if you want to manipulate the layer it returns, you'll need to address it like `parentLayer.subLayersByName("childLayer)[0].someproperty`

Josef Richter

I use

try myLayer.destroy

but myLayer needs to be instantiated beforehand at least a an empty object or variable, like

myLayer = {}

Read the entire post on Facebook