Saturday, April 30, 2011

Senocular Tint Snippet

http://board.flashkit.com/board/archive/index.php/t-730054.html
senocular
05-11-2007, 11:25 AM
here is an example using the Tween class with a tint. Assumes a movie clip with the instance name "clip"
import fl.transitions.*;
import fl.transitions.easing.*;

// function to transition from one colorTransform to another
function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;
}

// start and end colors for tween
var startColor:ColorTransform = new ColorTransform(); // default color, no tint
var endColor:ColorTransform = new ColorTransform();
endColor.color = 0xFF0000; // end color of red

// create tween; use "" for property since no
// property is being tweened; just using the
// Tween class here to handle the animation
// using the values 0 and 1 (0% to 100%)
// over a time period of 50 frames
var tween:Tween = new Tween(clip, "", Strong.easeOut, 0, 1, 50);
// listen for the TweenEvent.MOTION_CHANGE event to
// perform the custom color tween
tween.addEventListener(TweenEvent.MOTION_CHANGE, tweenTransform);

// TweenEvent.MOTION_CHANGE handler using interpolateColor
// to set the colorTransform of clip (tween.obj) based on
// the startColor and endColor properties defined earlier
function tweenTransform(event:TweenEvent):void {
// use tween position for interpolation of
// start and end colors (value 0 - 1)
clip.transform.colorTransform = interpolateColor(startColor, endColor, tween.position);
}


Note To Self: Don't forget drop shadows sometime.

No comments:

Post a Comment