Jump to content
GreenSock

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

Scope into Callback

Go to solution Solved by Carl,

Recommended Posts

Hello there,

 

I have tried to change boolean (this.stop)  value into the callback but It isn't work. I can get this using this:

    gsap.fromTo( cube.position,{ x: 150 }, { x: -150, duration:4,
        onComplete: this.finishGsap.bind(this),                 
        onCompleteParams: [ this.stop ]
    })

You can check into console this.stop value.

But I can't access to the methods of the tween like ( this.time()) and other solution was pass 'this' like a parameter but I'm sure this isn't a good idea.

I would like to use both into the callback.

 

Anybody can help me?

 

Thanks.

 

 

See the Pen BaQZXoZ by sanprieto (@sanprieto) on CodePen

Link to comment
Share on other sites

1 hour ago, Sanprieto said:

other solution was pass 'this' like a parameter but I'm sure this isn't a good idea.

Why is that? It seems like a good idea to me...

  • Like 3
Link to comment
Share on other sites

  • Solution

Thanks for the demo.

 

Please try setting callbackScope

 

gsap.fromTo( cube.position,{ x: 150 }, { x: -150, duration:1,
        onComplete: this.finishGsap,                 
        onCompleteParams: [ this.stop ],
        callbackScope: this
    })

 

in the demo below the console logs true when the tween is done

 

See the Pen LYbjYPB?editors=0010 by snorkltv (@snorkltv) on CodePen

 

this video may help as well

 

  • Like 4
Link to comment
Share on other sites

Ok perfect ! I thought that there was an other way..., but pass "this" like  parameter works perfect.

 

Thanks.

  • Like 1
Link to comment
Share on other sites

Note that you don't have to pass this.stop as a parameter if you're passing in the scope.

  • Like 2
Link to comment
Share on other sites

19 minutes ago, Carl said:

Wow!!! I understand now.
This video is really great and complete.
Thank you so much and congratulations Carl !

 

19 minutes ago, Carl said:

this video may help as well

 

 

  • Thanks 1
Link to comment
Share on other sites

Glad the video helped! You're welcome.

  • 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.
×