0
我正在使用EaselJS,我的任务是将.png从右向左移动。 由于我遇到了一个我无法修复的错误,我复制了一个具有相同目标的工作,并使用createjs.Ticker.addListener更新了所有内容。我打开包含JavaScript的其他index.html,它的工作完美。我开始使用这个代码作为例子,但是使用了我的图形。它几乎是相同的代码,但它仍然告诉我“TypeError:createjs.Ticker.addListener不是一个函数”我不知道为什么这个例子工作正常,但我的代码像这样搞砸了。为什么addListener不是一个函数?
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/easeljs.js"></script>
<script>
var canvas, stage, child;
function draw() {
canvas = document.getElementById("canvas");
stage = new createjs.Stage(canvas);
var bg = new createjs.Bitmap("bg.png");
stage.addChild(bg);
var child = new createjs.Bitmap("target.png");
child.onTick = function()
{
this.x --;
}
stage.addChild(child);
child.y = 100;
child.x = 100;
createjs.Ticker.useRAF = true;
createjs.Ticker.setFPS(1);
createjs.Ticker.addListener(stage , true);
createjs.Ticker.addListener(window , true);
}
</script>
</head>
<body onload="draw()">
<canvas id="canvas" width="650" height="400" style="background: #ccc;"></canvas>
</body>
</html>
编辑 已找到该错误。这不是代码,它是easelJS库本身造成的复杂性。我使用了不同版本的库,它工作。谢谢你:)。
这是正确的 - 但'的addListener()'是没有错的,它只是过时。 addListener方法在EaselJS的早期版本中(最高为0.4.2),并使用回调方法工作。 EaselJS 0.5.0引入了一个EventDispatcher方法,它与HTML DOM Level 3事件(像XHR,Images等使用的东西)具有同等的地位。 请注意,在EaselJS 0.7.0中添加了事件冒泡,使其更加强大! – Lanny