Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
e11

timeline.call() version 3 vs 2

Recommended Posts

The "this" was dropped in 3.0
.call( callback:Function, params:Array, position:* ) : self
vs
.call( callback:Function, params:Array, scope:*, position:* ) : *

 

scope: *

(default = null) — The scope in which the callback should be called (basically, what “this” refers to in the function). NOTE: this parameter only exists in the JavaScript and AS2 versions.

How do I port this code to GSAP3?


Here are the contents of a class method

timelineMax
.add([tmTitleSet, tmMetricSet, tmFooterSet])
.add([tmTitle])
.add([tmMetric, tmFooter])
.play()
.call(this.animationDone, null, this, "+=1");

Share this post


Link to post
Share on other sites

Don't know why that was dropped.

 

Just use bind. You can even include params.

 

 

gsap.timeline()
  .add(this.animationDone.bind(this), "+=1");

// with params
gsap.timeline()
  .add(this.animationDone.bind(this, "foo", "bar"), "+=1");

 

From the code you posted, it looks like you could also do this.

gsap.timeline({
  onComplete: this.animationDone,
  callbackScope: this
})
.add([tmTitleSet, tmMetricSet, tmFooterSet])
.add([tmTitle])
.add([tmMetric, tmFooter])
.set({}, {}, "+=1");

 

And I'm guessing that the play() call in there is unnecessary. Animations don't start playing until the next cycle.

 

  • Like 2

Share this post


Link to post
Share on other sites

@OSUblake, Thank you - bind() works perfectly.  The code with "Set" is generative and variable names need work.

gsap.timeline()
  .add(this.animationDone.bind(this, "foo", "bar"), "+=1");

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×