EaselJS:.addEventListener不是一个函数

时间:2015-02-19 11:47:39

标签: javascript html5-canvas addeventlistener easeljs

我正在尝试使用easelJS,有些东西我无法理解。 这里是 : 我有一个包含所有按钮的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); });
    }
}
}

这些名字按照我的预期给出,但是firebug警告我:

this[childName].addEventListener is not a function

并且没有显示任何内容。

在给出名称时,我确定这个[childName]是一个displayObject,所以我无法弄清楚为什么addEventListener不被视为函数。

任何人?

感谢。

1 个答案:

答案 0 :(得分:0)

好的,没关系。 Flash导出html文件与旧版本easelJS(easeljs-0.5.0.min.js)。当我加载最后一个版本easeljs-0.8.0.min.js时,我的代码开始工作了。

对不起。 感谢。