Tweening to a Relative Position using a Variable in TweenMax


/ Published in: ActionScript 3
Save to your folder(s)

If you want to tween an object relatively, but the new value changes and needs to be a variable, just cast it as a string.


Copy this code and paste it in your HTML
  1. // Your everyday absolute tween that moves movieclip_mc
  2. // to 100 on the x axis, taking one second to do so
  3. TweenMax.to(movieclip_mc, 1, {x:100});
  4.  
  5. // A relative tween that moves movieclip_mc to a
  6. // position on the x axis 100 units/pixels greater
  7. // than movieclip_mc's current position
  8. TweenMax.to(movieclip_mc, 1, {x:"100"});
  9.  
  10. // An absolute tween like the first, but passing in
  11. // the new value with a variable
  12. TweenMax.to(movieclip_mc, 1, {x:newX});
  13.  
  14. // A tween that casts the variable as a string,
  15. // thus making it a relative tween
  16. TweenMax.to(movieclip_mc, 1, {x:String(newX)});

URL: http://patrickmcd.com/2009/08/17/tweening-to-a-relative-position-using-a-variable-in-tweenmax/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.