Jump to content
Search Community

Real basic stuff, onUpdateParams syntax

lastnerve test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I've used TweenMax for Actionscript and onUpdateParams with multiple params and had no problems. However, I guess I don't understand the syntax of multiple params in onUpdateParams for Javascript.

 

The docs say that the params are an array, but if I code 'drawLine' to accept them as an array or as individual values it fails.

 

The code below is simply test code and wouldn't actually require a tween at all. If I remove the second param from onUpdateParams it works.

 

Please help.

function drawLine(i,sx){
$("#p1").append("i = " + i + " " + "<br />");
}

function tweenLine() {//
TweenMax.to(this, .5, {x:0, onUpdate:drawLine, onUpdateParams:[0,x]});
}
tweenLine();

Link to comment
Share on other sites

Hi,

 

From the code you have shown, it doesn't appear that you are defining x anywhere.

Even if x were defined somewhere its important to note that even if x changed while the tween was running, the tween would always pass the value of x as it was when the tween was first created. In other words, The onUpdateParams are not dynamic, they don't change as the tween runs.

You can solve this problem in 1 of 2 ways:

 

Pass in a reference to the object being tweened

 

 

function drawLine(i,obj){
$("#p1").append("i = " + i + " " + obj.x + "<br />");
}

function tweenLine() {//
TweenMax.to(this, .5, {x:0, onUpdate:drawLine, onUpdateParams:[0,this]});
}
tweenLine();

 

or you can self-reference the tween in a param like so

 

 

function drawLine(i, tween){
$("#p1").append("i = " + i + " " + tween.target.x + "<br />");
}

function tweenLine() {//
TweenMax.to(this, .5, {x:0, onUpdate:drawLine, onUpdateParams:[0, "{self}"] } );
}
tweenLine();

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