Today I’ve been setting up a very simple project – an intro animation and then some text/links fade in. The designers are making the animation and I’m just writing some basic code for the links etc (it’s CMS driven, many languages).

The client often like to change their minds (just a regular client then) and I know that the animation may change quite a bit. To fade the content in after the animation I am using addFrameScript.

However, a problem, I know the frame that the fading should take place on could change several (hundred) times before the project goes live. I could just tell the designers where in the code to change the frame number, but I thought of a nicer solution than that.

The code was a simple combo of addFrameScript and currentLabels. I got the designer to add a label on the frame they want the fading to take place and then used this simple code:

function addLabelScript(mc:MovieClip, label:String, func:Function):void
{
  var labels:Array = mc.currentLabels;
  var i:int = labels.length;
 
  while(--i > -1)
  {
    if(FrameLabel(labels[i]).name == label)
    {
      mc.addFrameScript(FrameLabel(labels[i]).frame - 1, func);
      return;
    }
  }
 
  trace("WARNING: The label '" + label + "' does not exist in the MovieClip '" + mc.name + "'");
}

OK it’s not going to make you fall off your chair with wonder but could be useful in the future. I’ve chucked it in a utils Class so it can be used like this:

function init():void
{
  Utils.addLabelScript(animation, "animation-complete", onComplete);
}

function onComplete():void
{
  trace("hello monkey I'm finished, do your fading thing");
}

In the above example the frame label the designer adds is “animation-complete”.