Search code examples
javascriptcreatejs

Create JS Stage events


"stagemouseup" already exists on the Stage object. If I add it like this would I get multiple callbacks?

stage.addEventListener("stagemouseup", function(){window.open(window.clickTag);});

In my local testing only 1 window launches so it seemed safe. However, after reading the docs it seems like this is the answer:

stage.on("stagemouseup", function(){window.open(window.clickTag);});

Can someone help me confirm?


Solution

  • If you add the listener multiple times, you will get multiple callbacks on each click.

    The on() method is a shortcut for addEventListener that has some syntactic sugar, such as:

    1. passing a scope parameter (and implicit scope if none is passed, instead of defaulting to window)
    2. A "run once" boolean
    3. a data object that is passed through the the handler

    There is also some functionality on the events dispatched by on(), which allow you to easily remove the handler.

    http://createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on