Jump to content
Search Community

x and y values not reported correctly after tween

GusAugust test
Moderator Tag

Recommended Posts

Why does the rendering work properly but the values after the tween are not correct?

var rect:Sprite = new Sprite;
rect.graphics.beginFill(0xFF0000);
rect.graphics.drawRect(0, 0, 20,20); // x, y, width, height
rect.graphics.endFill();
addChild(rect);

trace(rect.x, rect.y); // 0 0 correct

rect.x = rect.y = 100;
trace(rect.x, rect.y); // 100 100 correct

TweenMax.to(rect, 1, { x:200, y:200 } ); // renders properly on stage
trace(rect.x, rect.y); // 100 100 NOT CORRECT should be 200 200

Link to comment
Share on other sites

That's simply because your trace() is running immediately after you created your tween (but the tween hasn't actually finished running yet). This is totally expected behavior. It sounds like you thought the next line of code would literally wait 1 full second before executing, but that's not how Flash works. :) 

 

If your goal is to trace the values at the end of the tween, you can use an onComplete: 

TweenMax.to(rect, 1, { x:200, y:200, onComplete:function() {
    trace(rect.x, rect.y);
}} );
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...