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 this.name == "LayerA" print "LayerA" else print layer.name
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!
I'm not sure but would it work if it's this.name instead of layer.name?
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.
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?
Hmm good idea. Never tried that but I will give it a shot.
Try this:for layer in Framer.CurrentContext.getLayers() layer.onClick -> print this.name
I was also thinking about that.I came across the Framer dot CurrentContext just now
Could be a better option!
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.
Just curious, where did you find info about Framer.CurrentContext?
Awesome thx again. I searched the docs but found nothing. This will help!
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 [ layerA layerB ...]
Then added:for layer in hitLayers layer.on Events.Click, -> print this.name
Now I can quickly identify which hit layer is receiving my Click.