Jack,
Thank you for this handy function!
Openglpwr, the point of the functions that Jack provided is that they ensure exact timing as defined on the Flash IDE timeline instead of relying on numbers passed into greensock Tween constructors - "3" in the fromTo example you provided.
To get fromTo functionality and still preserve the nice timing you've set up in the Flash IDE you'd have to modify Jack's function a little bit:
public static function labelTweenDuration( mc:MovieClip, startLabel:String, endLabel:String, fps:Number=Nan ): Number
{
var labels:Array = mc.currentLabels;
if (isNaN(fps))
fps = (mc.stage != null) ? mc.stage.frameRate : 30;
var startFrame:int;
var endFrame:int;
//find the frame numbers of the labels we're tweening between
var i:int = labels.length;
while( --i > -1 )
{
if( labels[i].name == startLabel )
startFrame = labels[ i ].frame;
if( labels[i].name == endLabel )
endFrame = labels[ i ].frame;
}
return Math.abs(endFrame - startFrame - 1) / fps;
}
The main difference is that we're now calculating the number of frames between the startLabel and endLabel, not the currentFrame and endLabel.
Similarly, we have to make a tiny tweak to the createLabelTween to take in a second label parameter as follows:
public static function createLabelTween( mc:MovieClip, startLabel:String, endLabel:String, fps:Number = NaN ): TweenLite
{
return TweenMax.fromTo( mc, labelTweenDuration( mc, startLabel, endLabel, fps ),
{ frameLabel:startLabel }, { frameLabel:endLabel, ease:Linear.easeNone });
}
To wrap things up, with these two functions, openglpwr's Tween changes from
TweenMax.fromTo(MC_Anim, 3, {frameLabel:"move_start"}, {frameLabel:"move_end",ease:Linear.easeNone});
to
createLabelTween( MC_Anim, move_start, move_end );
and best of all, it is now guaranteed to preserve the timing that was defined in the Flash IDE, not the possibly arbitrary value of 3 seconds.