简体   繁体   English

dynamicjs“无法调用未定义的方法'appendChild'”

[英]kineticjs “cannot call method 'appendChild' of undefined”

I am only starting to use kineticJS but I am getting some errors after following This tutorial 我只是开始使用dynamicJS,但是按照教程操作后会出现一些错误

I don't understand why but I am getting an exception from inside the KineticJS file: 我不明白为什么,但是从KineticJS文件内部收到异常:

"Uncaught TypeError: cannot call method 'appendChild' of undefined".

When I do a step by step alert() s, I see that it stops after 当我逐步执行alert() ,我看到它在之后停止

var stage = new Kinetic.Stage("rightSide", 578, 200); var stage = new Kinetic.Stage(“ rightSide”,578,200);

but I most definitively have: 但我最确定的是:

 <canvas id="rightSide"> </canvas> 

I also tried: 我也尝试过:

 <div id="rightSide"> </div> 

and I am getting the same error. 和我得到同样的错误。

Thanks. 谢谢。

Edit: in response to the comments below, this is Copy-Paste from the tutorial: 编辑:针对以下评论,这是本教程中的复制粘贴:

 </head> <body> <div id="container"> </div> </body> 

the problem was with the actual creation of the stage. 问题在于舞台的实际创建。

instead of 代替

var stage = new Kinetic.Stage("container", 578, 200); var stage = new Kinetic.Stage(“ container”,578,200);

i did 我做到了

var stage = new Kinetic.Stage({ container: "container", width: 578, height: 200 }); var stage = new Kinetic.Stage({container:“ container”,width:578,height:200});

There is a change in Kinetic.Stage constructor since March https://github.com/ericdrowell/KineticJS/commit/7ced50f6943af544dbdfc95883ec41728db1d3bd 自3月以来,Kinetic.Stage构造函数发生了变化https://github.com/ericdrowell/KineticJS/commit/7ced50f6943af544dbdfc95883ec41728db1d3bd

Thus @Gleeb 's own answer reflects current practice in KineticJS v4.0.x instead of those docs / tutorials made in the early v3 era. 因此,@ Gleeb自己的答案反映了KineticJS v4.0.x中的当前实践,而不是早期v3时代中的那些文档/教程。


Should make a pull request for backward compatibility.. something like 应该提出向后兼容的请求。

if(arguments.length>1){
 config.container =  arguments[0];
 config.width = arguments[1];
 config.height = arguments[2];
}

... in the Stage constructor. ...在舞台构造函数中。

Try to run your script at the window.onload event (as in the example) and use console.log() to debug your variables/objects. 尝试在window.onload事件(如示例中)中运行脚本,然后使用console.log()调试变量/对象。

window.onload = function() {
  var stage = new Kinetic.Stage("rightSide", 578, 200);
  console.log('stage =', stage); // DEBUG
};

...and use the div and not the canvas . ...然后使用div而不是canvas

<div id="rightSide"></div>

You´ll find more tutorials and the official API documentation at http://www.kineticjs.com/docs/symbols/Kinetic.Stage.php 您可以在http://www.kineticjs.com/docs/symbols/Kinetic.Stage.php中找到更多教程和官方API文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM