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

What is Framer? Join the Community
Return to index
Björn Mußmann
Posted Jan 23 - Read on Facebook

Hey there!

My question is: Why is the parent undefined?

TypeError: undefined is not an object (evaluating 'layer._element.appendChild')

Or: How can I use the value of the variable "name" instead of "testSwitch"?

5 Comments

JL Flores Mena

The parent attribute expects a layer instance (testSwitch, in your example) not a String value ("testswitch"). What you're passing here is just a String, not a reference to another layer.
myLayer.name will always return a String, so you can't use a layer's name attribute to set parents. I may need to know what you're trying to do here to give you a better solution, but in this case the parent should just be testSwitch.

Björn Mußmann

I like to use createSwitch() more than once and control the name of testSwitch by the parameter I pass to the function...

Jordan Robert Dobson

You're thinking about this wrong... here's how I would approach it.

What things are called inside that function doesn't really matter.

Have your function return the testSwitch layer and name it before you call function.

testSwitch = createSwitch()

Inside your function

createSwitch = ->
foo = new Layer
name: "whatever"

FooBg = new Layer
parent: foo

return foo

That should essentially do what you want.

Name is just a nickname not actual variable name.

Jordan Robert Dobson

Also that! I had that all typed out an I'm pretty sure my son jumped on me and I put the phone down and played legos instead. 😅

Read the entire post on Facebook