Is there a way to clear events on a layer?
I would like to have one button that can do different things depending on where in the prototype I am.
so ish like this:
button = new LayerBlah blah
button.on Events.TouchEnd, -> layerX.states.swich(Blah blah)
But later on I want the layer to only do this:
button.on Events.TouchEnd, -> layerY.states.swich(Blah blah)
So can I somehow clear the events before adding the new one?
yes, you can use the "off" function to remove the event listener:
layerA.on(Events.Click, clickHandler)layerA.off(Events.Click, clickHandler)
Protip: you also have .once to just do something one time.
I can't get the once to work, but I found a workaround and using swichInstant on the states so the solution is ugly but working.
button.once Events.TouchEnd, ->layerX.states.swichInstant("show")
button.once Events.TouchEnd, ->layerX.states.swichInstant("hide")layerY.states.swichInstant("show")