Jump to content
Search Community

get mid-tween width/height in onUpdate function [SOLVED]

sideDoor test
Moderator Tag

Recommended Posts

Hello,

 

I'm tweening the width and height of a Sprite. I want to send the mid-tween width and height values of that Sprite to another function, where those values will be referenced to proportion another display object. I thought I could use the onUpdate function, figuring that every time it is called during the tween, that the values of mySprite.width and mySprite.height would equate to the Sprite's mid-tween width/height. But I simply get the original width and height over and over again until the tween ends.

 

I was trying this:

 

public function tweenSprite(e:MouseEvent):void
{
    // say that the Sprite's original w/h is 60x60px
    TweenLite.to(mySprite, 1, {width:400, height:400, onUpdate:myUpdateFunction, onUpdateParams:[mySprite.width, mySprite.height]});
}

// update function
public function myUpdateFunction(width:Number, height:number):void
{
    trace(width);
}

 

So, say the Sprite is originally 60x60px, and I am tweening it to 400x400px, I thought the myUpdateFunction method would receive increasing width/height values every time onUpdate is called, but instead I get the Sprite's original proportions, 60px, over and over again until the Sprite is finished being tweened.

 

Any ideas on how to get the mid-tween proportions?

 

Thanks,

sd

Link to comment
Share on other sites

The updateParams are stored at the start of the tween. Try passing the sprite instead like this:

 

function tweenSprite(e:MouseEvent):void
{
TweenLite.to(mySprite, 1, {width:400, height:400, onUpdate:myUpdateFunction, onUpdateParams:[mySprite]});
}

function myUpdateFunction(target:Sprite):void
{
trace("width = " + target.width + " height = " + target.height);
}

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