Jump to content
Search Community

OnComplete gives me a value as it was before the tween

gigbig test
Moderator Tag

Recommended Posts

Hi, I am using TweenLite with Away3D, and I am rescaling a Mesh with an Elastic tween: the code is as follows

 

TweenLite.to(this, magnifyTime, {x: this.x + deltaX, z: this.z + deltaZ, y: this.y * zoomScale, scaleX: diceScale * zoomScale, scaleY: diceScale * zoomScale, scaleZ: diceScale * zoomScale, onUpdate: updateShadow(), ease: Elastic.easeOut, onComplete: trace, onCompleteParams: ["this.scaleX = " + this.scaleX]} );

My problem is that the mesh (this) scales correctly, multiplying the initial scale 1 by 2.5, obtaining a 2.5 scale, but when the tween reaches the onComplete event it traces "1"!

 

WHY?! Am I missing a stupid detail I can't see?

I need to update the shadow in the onUpdate event, but if I can't get the correct mesh scale it remains unchanged! The onComplete event it just a test, I will delete it: I need the changing value of the scale, but the tween register the initial value, so... who can I constantly update the shadow with the correct scale?

Link to comment
Share on other sites

Hi,

 

There are 2 things that need to be addressed here. I've simplified the code for the sake of clarity.

 

TweenLite.to(mc, 1, {x:500, onUpdate:updateShadow(), onComplete:someFunction, onCompleteParams:[mc.x]});

 

There are 2 problems with the code above:

 

1: you need to remove the () in updateShadow(). If you use updateShadow() that tells Flash to execute that function immediately. You need only specify the name of the function:

onUpdate:updateShadow

 

2: The expression in the onCompleteParams is evaluated the instant the TweenLite is created. This has to do more with the way actionscript works than anything to do with TweenLite. That is why the onComplete function was using the value that existed when your tween was created.

 

the simplified code modified to work as intended would look like this:

 

TweenLite.to(mc, 1, {x:500,onUpdate:updateShadow, onComplete:someFunction, onCompleteParams:[mc]});

function someFunction(obj:MovieClip):void{
trace(obj.x) // 500
}

 

hopefully that helps you see how your more elaborate tween can be edited.

Link to comment
Share on other sites

Ah! oNComplete is evaluated at the tween creation? Good to know, so I have to call an external function.

 

I didn't know that () means "execute immediately": what does this imply? Does it execute it just once at the first tween step?

 

Thank you Carl! ;)

Link to comment
Share on other sites

If you do something like

 

TweenLite.to(mc, 1, {x:100, onComplete:someFunction()})

 

someFunction() will run immediately totally independent of the tween. Putting in the () as shown above is a fairly common mistake. Just remember when specifying which function to use as a callback, just pass the name of the function.

 

GOOD:

TweenLite.to(mc, 1, {x:100, onComplete:someFunction})

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