Jump to content
Search Community

Is it possible to change y value using onUpdate

Guest docTorbin
Moderator Tag

Recommended Posts

Guest docTorbin

We are using tweenlite to move an item that has the potential to be animating when the user also clicks full screen. If left unchecked, this could result in a malformed animation. I see that we can check each state with onUpdate but how would we go about changing the value of y? For example, here is our call:

 

TweenLite.to(mySprite, .5, {y:totalHeight - 43, ease:Back.easeOut, easeParams:[.75], onUpdate:checkTotalHeight, onUpdateParams:[ ? ]});

 

What could we pass via onUpdateParams that would allow us to change y?

 

Thanks!

Link to comment
Share on other sites

in the onUpdateParams you would include any paramaters that your checkTotalHeight function needs to operate. I don't know exactly what checkTotalHeight() does so I can't recommend what the params should be. in some situations you would pass in the target of the tween, so you may do something like

 

onUpdateParams:[mySprite]

 

but i don't think that is necessary for what you are doing.

 

 

 

Ultimately you are probably going to want to use TweenMax's updateTo() method which will allow you to set a new x value for the destination.

 

consider the following example:

 

var tween:TweenMax = TweenMax.to(mc, 4, {x:400});

stage.addEventListener(MouseEvent.CLICK, updateTween);

function updateTween(e:MouseEvent):void{
       tween.updateTo({x:0});
}

 

using the above code, the tween will start moving mc to an x of 100, when you click anywhere on the stage the tween will proceed to move mc back to an x of 0.

 

also, it is totally reasonable that when you detect that the height of the stage has resized you can just recreate the tween as well.

 

so basically you need checkTotalHeight() to determine whether or not the tween needs to be changed. When that condition is true, either use updateTo() to set a new x value or create a new tween. updateTo() has the advantage of honoring the tween's current timing.

 

keep in mind that if you use updateTo() you may also want to enforce that the onUpdate callback isn't still firing after the tween has been given a new x value. You can null it out like so

 

tween.updateTo({x:0, onUpdate:null});

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