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

What is Framer? Join the Community
Return to index
Brian Byle
Posted May 09 - Read on Facebook

Hello again!

For testing, I was looking to write a statement that would print back the name of whatever layer I clicked in Framer.

What I tried:
layer.on Event.Click, ->
If == "LayerA"
print "LayerA"

Surprise this doesn't work. Again the goal is to return the name of whatever layer was clicked as a print statement. Ideas?

That again in advance!


Geunbae Lee

I'm not sure but would it work if it's instead of

Brian Byle

I tried that but it didn't work. I am not sure if layer.on Events.Click.... binds to any layer. My click event may not even be "heard" because nothing may be listening.

I am trying to create an anonymous listener.

Geunbae Lee

How about creating an array without anything in it and push whichever layer you click to that layer and print its name?
Once it's printed, then the array is reset.

Would this work?

Brian Byle

Hmm good idea. Never tried that but I will give it a shot.

Andreas Wahlström

Try this:
for layer in Framer.CurrentContext.getLayers()
layer.onClick -> print

Geunbae Lee

I was also thinking about that.
I came across the Framer dot CurrentContext just now

Could be a better option!

Brian Byle

Andreas that seemed to work. My layers are imported from Sketch, so not only does it print my current clicked item, but also the name of the Artboard name from Sketch.

But as long as it returns the clicked layer name that should work fine. Thx all.

Brian Byle

Just curious, where did you find info about Framer.CurrentContext?

Brian Byle

Awesome thx again. I searched the docs but found nothing. This will help!

Brian Byle

Hey guys I just found an easier way to do this:

Placed all of my hit layers(layers I created to only receive click events into an array:
hitLayers [

Then added:
for layer in hitLayers
layer.on Events.Click, ->

Now I can quickly identify which hit layer is receiving my Click.

Read the entire post on Facebook