Tweening to a Relative Position using a Variable in TweenMax

This isn’t too complicated, but it’s something I hadn’t come across until a few days ago. 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.

// Your everyday absolute tween that moves movieclip_mc
// to 100 on the x axis, taking one second to do so
TweenMax.to(movieclip_mc, 1, {x:100});

// A relative tween that moves movieclip_mc to a
// position on the x axis 100 units/pixels greater
// than movieclip_mc's current position
TweenMax.to(movieclip_mc, 1, {x:"100"});

// An absolute tween like the first, but passing in
// the new value with a variable
TweenMax.to(movieclip_mc, 1, {x:newX});

// A tween that casts the variable as a string,
// thus making it a relative tween
TweenMax.to(movieclip_mc, 1, {x:String(newX)});

If you’re not using TweenMax/TweenLite, do yourself a favor and give it a try.

This entry was posted in Flash, Tutorials. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted August 26, 2009 at 7:46 am | Permalink

    Thanks for listing this. Being self taught in Actionscript, it’s really tough to know what tags are available for me without being told. I wouldn’t even thought there would be one for relative tweens.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Categories

    • Awards
    • Branding
    • Clients
    • Cool
    • Flash
    • Motown
    • Portfolio
    • Tutorials
    • Uncategorized
  • Archives

    • 2010 (5)
    • 2009 (10)
    • 2008 (10)
    • 2007 (5)
    • 2005 (2)
    • 2002 (2)
    • 2001 (2)