Search code examples
easeljscreatejs

Class Extends Container But Can't Add Event Listener?


I created a custom class extending Container. However, when I try to add a listener to it, I get the following errors:

"TypeError: this.addEventListener is not a function

Here's a minimal example of my code:

(function() {
    var ExtendedContainerObject = function() {
        this.initialize();
    }

    // inherit from Container
    var p = ExtendedContainerObject.prototype = new createjs.Container();

    p.Container_initialize = p.initialize;
    p.initialize = function() {
        this.Container_initialize();
        console.log("this: " + this);
        this.addEventListener("custom_event", function(evt){console.log("this: " + evt.target);});

        this.button.onPress = function(evt) {
            evt.onMouseMove = function(ev) {
                dispatchEvent(new Event("custom_event", this));
            }
        }
    }

    window.ExtendedContainerObject = ExtendedContainerObject;
}());

Solution

  • I have a class that uses this excactly the same way, it should work, are you using EaselJS 0.6.0?