Jump to content
Search Community

access each tween in timeline

Daniel2024 test
Moderator Tag

Recommended Posts

Hello,

 

i created a timeline and want to access each tween individually. How can i do it?

 

Furthermore i want to add a general function to the end of each tween. I used .add() after each tween, but is there another way to solve this?

 

Thank you in advance.

 

Regards Daniel

Link to comment
Share on other sites

Thank you.

 

const tweens = timeline.getChildren();

for(var i = 0; i < tweens.length; i++) {
   if(tweens[0].progress() === 1){
      console.log('hit');
   }
}

Here, i wanted to console log , after the the first tween of the timeline ends. What i am doing wrong?

Link to comment
Share on other sites

1 hour ago, Daniel2024 said:

Here, i wanted to console log , after the the first tween of the timeline ends. What i am doing wrong?

That loop will run immediately when invoked and since it is likely running before the end of the tween finished, the tween's progress won't be 1. But even if it was ran after the tween completed it wouldn't fire right after the tween completes, it'd just fire whenever the loop is ran.

 

What you want to use instead is a callback, specifically the onComplete callback for the tween. If you can, it's generally more convenient to add the callback when you create the tween:

.to(elem, {..., onComplete: () => console.log("hit") })

But you can add it later if you need to by using eventCallback():

timeline.getChildren()[0].eventCallback("onComplete", () => console.log('hit') );

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...