【发布时间】:2015-04-20 18:00:25
【问题描述】:
我正在尝试使用画架JS,但有些东西我无法理解。 这里是 : 我有一个包含我所有按钮的 MC。像这样(PE 和 CO 是我的按钮。它们之前在我的代码中已经初始化):
(lib.buttonsContainer = function() {
this.initialize();
// Layer 1
this.PE = new lib.PE();
this.PE.setTransform(121,163.3,2.382,2.382);
this.CO = new lib.CO();
this.CO.setTransform(135.2,59.9,2.382,2.382);
this.addChild(this.PE, this.CO);
//I give a name and an action
for(var childName in this){
if(this[childName] instanceof createjs.DisplayObject) {
this[childName].name=childName;
console.log(childName+" now has a name!!"); // it works.
this[childName].addEventListener("click", function(evt) { alert(evt.target.parent.name); });
}
}
}
名字如我所料,但萤火虫警告我:
this[childName].addEventListener is not a function
什么都没有显示。
由于给出了名称,我确定 this[childName] 是一个 displayObject,所以我无法弄清楚为什么 addEventListener 不被视为一个函数。
有人吗?
谢谢。
【问题讨论】:
标签: javascript html5-canvas addeventlistener easeljs