0

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;
}());
gion_13
  • 41,171
  • 10
  • 96
  • 108
Ricebandit
  • 233
  • 4
  • 12

1 Answers1

1

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

olsn
  • 16,644
  • 6
  • 59
  • 65
  • 1
    Yes, EventDispatcher was only added in 0.6.0. If you have an older version, you will have to use callbacks. – Lanny Feb 28 '13 at 22:41
  • Thank you! This was my first "real" easelJS project and forgot how long ago I started with these files! haha – Ricebandit Mar 06 '13 at 15:41