簡體   English   中英

tween.addEventListener不是第二次調用時的函數

[英]tween.addEventListener is not a function when called for the second time

我創建了一個補間動畫,如下所示:

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不是函數,因此未注冊update事件,因此動畫不會運行我的更新代碼。 但是,當動畫結束時,它將在“完成”上運行代碼。

但是,如果我執行以下任何操作:

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

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

});

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

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

});

它將在最后一個“ addEventListener”中始終給出錯誤。 因此,如果我先添加“更新”,動畫將正常工作,但不會執行完成代碼。

根據文檔,“更新”和“完成”都是事件

為什么我只能添加事件之一?

我的猜測是它不返回補間對象,而是其他一些事件引用,因此中斷了鏈

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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM