0

我创建了一个像这样的补间动画:

var tweenLight = new createjs.Tween(mycolor,{loop:9})
.to({r:1},500)
.to({r:0},500)
.addEventListener('complete',function() {
    // code to be executed when tween is completed
});
tweenLight.addEventListener('change',function() { // <--- not a function
    // code to be executed each frame
});

执行此代码时,它给了我一个错误,addEventListener 不是函数,在第 7 行,因此未注册更新事件,因此动画不会运行我的更新代码。但是,当动画结束时,它会在“完成”时运行代码。

但是,如果我做以下任何事情:

(..).addEventListener('complete',function() {

}).addEventListener('change',function() { // <--- still not a function

});

.

(..).addEventListener('complete',function() {

})
tweenLight.addEventListener('change',function() { // <--- still not a function

});

它总是会在最后一个“addEventListener”中出错。因此,如果我先添加“更新”,动画将正常工作,但不会执行完成代码。

根据文档,“更新”和“完成”都是事件。

为什么我只能添加一个事件?

4

1 回答 1

2

我的猜测是它不返回补间对象,而是一些其他事件引用,所以打破了链条

var tweenLight = new createjs.Tween(mycolor, {
    loop: 9
  })
  .to({
    r: 1
  }, 500)
  .to({
    r: 0
  }, 500);
tweenLight.addEventListener('complete', function() {
  // code to be executed when tween is completed
});
tweenLight.addEventListener('change', function() { // <--- not a function
  // code to be executed each frame
});
于 2017-12-12T00:30:29.533 回答