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., 1, {x:100});
  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., 1, {x:"100"});
  10. // An absolute tween like the first, but passing in
  11. // the new value with a variable
  12., 1, {x:newX});
  14. // A tween that casts the variable as a string,
  15. // thus making it a relative tween
  16., 1, {x:String(newX)});


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.