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

What is Framer? Join the Community
Return to index
Peter Lada
Posted Aug 27 - Read on Facebook

Does anyone else have issues with unbinding events in Framer? I've recently run into this issue quite a few times. Is this a known issue?


Joshua Tucker

Hey Peter! When you say unbind, do you mean

How are setting the original listener and what issues are you running into?

Peter Lada

Joshua Tucker

card.on Events.DragStart, dragStart.bind(null, this) Events.DragStart, dragStart

seems fairly straightforward, but perhaps I'm doing something obviously wrong

Joshua Tucker

Peter Lada No worries! Let me explain it in the best way I can (I'm learning too).

If you wish to keep the context of this, you can use Coffeescript's fat arrow – So you would use:

card.on Events.DragStart, =>

Based on my experience, binding outside of a creating a class isn't really an issue. From what I've seen, in Framer events, the last argument is always the reference to the layer. This is also the layer too. So you can do something like:

card.on Events.DragStart, (event, layer) ->
# layer is referencing card
print layer
# this is also card
print this

As for unbinding, to my knowledge, you can't remove/unbind a listener that is anonymous function. That's simply because it has no reference to the function in order to actually remove it. Binding always creates an anonymous function so you're stuck there.

The only way to be able to remove an event listener is to give it an explicit handler function.

printFunc = ->
print "Printing!"

# On DragStart, the event is handled inside of printFunc
card.on Events.DragStart, printFunc

# Later in my code...
# Since an explicit handler is given, it has a reference and removes it. Events.DragStart, printFunc

Let me know if this addresses your question!

Fran Pérez

Joshua right on the spot, as always :)

You can also use .once instead of .on, which basically fires the event just one time:

card.once Events.Click, foo

Jordan Robert Dobson

I always forget about .once... Thanks for the reminder guys.

Peter Lada

It wasnt a fat arrow issue, it was that i was rebinding the event through another event listener which I forgot about :) thanks though! Also, I didnt realize .once was also a framer thing, thats cool.

Joshua Tucker

Right on man! Glad you got it figured out.

Peter Lada


Read the entire post on Facebook