0

I am using EaselJS and my task is to move a .png from right to left. Since I bumped into an error I can't fix, I copied a work with the same goal and using createjs.Ticker.addListener to keep everything updated. I opened the other index.html with the included javascript and it worked perfectly. I proceeded to use this code as an example, but used my graphics. It is almost the same code, but it still tells me "TypeError: createjs.Ticker.addListener is not a function" I have no idea why the example works fine, but my code screws up like that.

<html>
    <head>
        <title>Title</title>
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <script src="js/easeljs.js"></script>

    <script>

        var canvas, stage, child;

        function draw () {

            canvas = document.getElementById("canvas");
            stage = new createjs.Stage( canvas );

            var bg = new createjs.Bitmap( "bg.png" );
            stage.addChild( bg );

            var child = new createjs.Bitmap( "target.png" );
            child.onTick = function ()
            {
                this.x --;
            }


            stage.addChild( child );
            child.y = 100;
            child.x = 100;


            createjs.Ticker.useRAF = true;
            createjs.Ticker.setFPS( 1 );
            createjs.Ticker.addListener( stage , true );
            createjs.Ticker.addListener( window , true );
        }

    </script>

</head>
<body onload="draw()">
    <canvas id="canvas" width="650" height="400" style="background: #ccc;"></canvas>
</body>
</html>

EDIT The error has been found. It wasn't the code, it was the easelJS-library itself that made the complications. I used a different version of the library and it worked. Thank you anyways :).

Rawfish
  • 13
  • 1
  • 3

1 Answers1

1

The function you are after is addEventListener

like this:

createjs.Ticker.addEventListener("tick", handleTick);
function handleTick() {
    stage.update();
}

CreateJS Ticker Documentation

rorypicko
  • 4,194
  • 3
  • 26
  • 43
  • 2
    This is correct - but `addListener()` is not wrong, its just deprecated. The addListener approach was in early versions of EaselJS (up to 0.4.2), and works using a callback approach. EaselJS 0.5.0 introduced an EventDispatcher approach, which has parity with HTML DOM Level 3 events (which things like XHR, Images, etc use). Note that in EaselJS 0.7.0, event bubbling was added, making it even more powerful! – Lanny Jan 14 '14 at 15:28