我创建了一个这样的补间动画:
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
});
当执行此代码时,它会在第7行给出错误,addEventListener不是函数,因此更新事件未注册,因此动画不会运行我的更新代码。但是,当动画结束时,它会在“完成”上运行代码。
但是,如果我做了以下任何事情:
(..).addEventListener('complete',function() {
}).addEventListener('change',function() { // <--- still not a function
});
(..).addEventListener('complete',function() {
})
tweenLight.addEventListener('change',function() { // <--- still not a function
});
它总是会在最后一个'addEventListener'中出错。因此,如果我先添加“更新”,动画将正常运行,但不会执行完成代码。
根据文档,“更新”和“完整”均为events。
为什么我只能添加其中一个事件?
答案 0 :(得分: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
});