Pergunta

In the beginning of my code, I set a tick event. These 3 following lines work.

createjs.Ticker.addEventListener("tick", handleTick);
createjs.Ticker.useRAF = true;
createjs.Ticker.setFPS(30);

I would like to remove the listener at the end of my code. I tried to call it like that but it doesn't work:

createjs.Ticker.removeAllListeners();

The Firefox console says me createjs.Ticker.removeAllListeners is not a function. So i tried to switch to the other one:

createjs.Ticker.removeEventListener("tick", handleTick);

And It also doesn't work. I don't really know how to use it. On the official website they use it with a displayObject, but I don't create it link to a button or something else.

http://www.createjs.com/Docs/EaselJS/classes/Ticker.html#method_removeAllEventListeners

Could someone could help me to solve it please ?

Thanks

EDIT: I'm using the easelJS version 0.7.1 but I think my problem is linked to a tutorial using an older version of easelJS (0.5). Does anyone know how to adapt it the the latest version of easelJS ? thanks

EDIT 2: I found on this link (http://www.createjs.com/Docs/EaselJS/modules/EaselJS.html) the utilization of createjs.Ticker.addEventListener("tick", handleTick); in the latest version of easelJS, but there is no documentation about how to remove the listener called from createjs.Ticker, i'm still looking for a solution

Foi útil?

Solução

I think the function you are looking for is:

createjs.Ticker.removeAllEventListeners(); // Note the function name

The second example should work, assuming you are not proxying the function to maintain scope. Ticker is an EventDispatcher, and inherits all the methods defined here: http://www.createjs.com/Docs/EaselJS/classes/EventDispatcher.html

The evt.remove() is a great shortcut, if you don't have a reference to the function.

One important note: If you remove ALL event listeners from Ticker, you may inadvertedly stop Tween from working. Tween adds a listener when it is initialized. Your best option is the second option where you remove the listener entirely. If you still can't get it working, feel free to post some more code, and I will try and help out.

Cheers.

Outras dicas

I use the // alternately: evt.remove(); call. Using a global var, when I set this one to true, I call the evt.remove() function. But It might not be the best way to do it.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top