2013-02-28 91 views
0

我創建了一個擴展容器的自定義類。然而,當我嘗試將監聽器添加到它,我得到以下錯誤:類擴展容器但不能添加事件監聽器?

「類型錯誤:this.addEventListener不是一個函數

這裏是我的代碼小例子:

(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; 
}()); 

回答

1

我有一個類,使用這excactly相同的方式,它應該工作,你使用EaselJS 0.6.0?

+1

是的,EventDispatcher只在0.6.0添加如果你有一箇舊版本,你將不得不使用回調。 – Lanny 2013-02-28 22:41:35

+0

謝謝!這是我第一個「真正的」easelJS項目和忘記了多久以前我開始使用這些文件了!哈哈 – Ricebandit 2013-03-06 15:41:29