Jump to content
Search Community

Scope into Callback

Sanprieto test
Moderator Tag

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

  • 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

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