Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获类型错误:child.dispatchEvent不是函数EaselJS_Javascript_Jquery_Debugging_Createjs_Easeljs - Fatal编程技术网

Javascript 未捕获类型错误:child.dispatchEvent不是函数EaselJS

Javascript 未捕获类型错误:child.dispatchEvent不是函数EaselJS,javascript,jquery,debugging,createjs,easeljs,Javascript,Jquery,Debugging,Createjs,Easeljs,我正在尝试使用创建一个纸牌游戏。我在尝试将对象类添加到stage时出现了uncaughttypeerror:child.dispatchEvent不是函数EaselJS错误。我使用的是jQuery,但我遵循以下步骤删除jQuery冲突: <script src="lib/jQuery.js"></script> <script>jQuery.noConflict();</script> 卡类:我正在控制台上记录画布,以确保我没有丢

我正在尝试使用创建一个纸牌游戏。我在尝试将对象类添加到stage时出现了
uncaughttypeerror:child.dispatchEvent不是函数EaselJS
错误。我使用的是
jQuery
,但我遵循以下步骤删除jQuery冲突:

    <script src="lib/jQuery.js"></script>
    <script>jQuery.noConflict();</script>
卡类:我正在控制台上记录
画布
,以确保我没有丢失上下文,并且它实际上记录了正确的Stage对象

var Card = function(canvas, args) {

    var graphics = new createjs.Graphics();
    graphics.beginStroke("red").beginFill("blue").drawRect(20, 20, 100, 50);
    this.shape = new createjs.Shape(graphics);
    this.set = new createjs.Container();
    this.set.addChild(this.shape);
    this.set.x = this.x;
    this.set.y = this.y;
    console.log('canvas', canvas);  //outputs createJS Stage object
    canvas.addChild(this); //Error seems to be because of this
我还尝试将卡添加到创建循环中:

for ...
     for ...
         var card = new Card(this.tableCanvas, card_data);
         this.tableCanvas.addChild(card); 
     }
}
同样的错误

HTML代码片段:

this.tableCanvas = new createjs.Stage('Table');

function createDeck () {

        for (var i = 0; i < suits.length; i++) {
                for (var j = 0; j < values.length; j++) {
                    var card_data = { ... };
                    var card = new Card(this.tableCanvas, card_data);
                    ...
                }
         }
         this.tableCanvas.update();
<body>
    <div id="GameBoard">
        <canvas id="Table" width="1000" height="1000"></canvas>
    </div>
</body>

错误:createjs-2015.11.26.combined.js:7322

p.addChild = function(child) {
    if (child == null) { return child; }
    var l = arguments.length;
    if (l > 1) {
        for (var i=0; i<l; i++) { this.addChild(arguments[i]); }
        return arguments[l-1];
    }
    if (child.parent) { child.parent.removeChild(child); }
    child.parent = this;
    this.children.push(child);
    child.dispatchEvent("added"); //ERROR HERE
    return child;
};
p.addChild=function(child){
如果(child==null){return child;}
var l=arguments.length;
如果(l>1){

对于(var i=0;i我认为这是因为您正在将卡实例添加到stage。stage子项需要是DisplayObjects。您应该添加
此项。改为将
设置到
画布中

我还要推荐你的第二种方法

this.tableCanvas.addChild(card.set);