Comment icon 0
Programmatic Tweening

Doing tween animations in Flash using code rather than via the timeline sometimes comes in handy. While it may be harder to visualize, it is a great deal more flexible than timeline animation.

In the project I’m working on now, there is a drop-down menu that requires opening and closing animation upon rollover/rollout. Before, I’d do this with timeline animation combined with the old-school “gotoAndPlay()” to jump to different parts that animate opening and closing. However I’ve found that this makes the animation appear jerky if you hover your mouse over and then really quickly move it away. A better way is using tweens:

import fl.transitions.Tween;
import fl.transitions.easing.*;

var slideMenuOut:Tween = new Tween(galleryMenu, "y", Regular.easeOut, header.galleryMenu.galleryBg.y, 0, 9);

The constructor takes a heck of a lot of arguments that I always have trouble remembering:

  • object to tween
  • property to tween (don’t forget the quotes)
  • the easing method to use (refer to the fl.transitions package for all the possibilities)
  • starting value (set this to whatever the current value may be, so there is no jerkiness)
  • ending value
  • length, in frames (or seconds, if last parameter is true)
  • whether the length unit is seconds (optional)