(transShift)

Color.prototype.transShift = function(){
        //trace("Running");
        var ratio = (getTimer()-this.v.startTime)/this.v.milSecs;
        if(ratio<1){
                var newTrans = {};
                for(var i in this.v.change){
                        newTrans[i] = this.v.startTrans[i]+ratio*this.v.change[i];
                }
                this.setTransform(newTrans);
        }else{
                this.setTransform(this.v.goalTrans);
                clearInterval(this.v.intrvl);
                var myFunc = this.v.func;
                delete(this.v);
                if(myFunc)myFunc();
        }
}

Purpose:
TransShift creates a transformation object with values between the startTans and goalTrans objects. In other words it's responsible for making the gradual color change.

Explanation:

Color.prototype.transShift = function(){

This function accepts no arguments since all necessary information is stored within the "V"ariables object inside each instance of the Color object.

//trace("Running");

You can remove the comment marks from this line to see when the Color object is fading in the testing environment.

var ratio = (getTimer()-this.v.startTime)/this.v.milSecs;

The ratio is used as a way of determining how far along you are in the fading process. A ratio with a value of 0 means you have just started the fade while a value of 1 means you are at the very end of a fade. If you started the fade 5 seconds into the SWF's life span, startTime will hold a value of 5000. If your color fade lasts 1 second then milSecs will hold a value of 1000. If the current time is 5 and a half seconds into the SWF's life span then getTimer() will return a value of 5500. This leaves the equation of (5500-5000)/1000 which equals 500/1000 which equals 1/2. This means the color fade is 50% complete.

if(ratio<1){

If the ratio is less than 1 then there is still some color fading left to do so don't slack-off just yet.

var newTrans = {};

NewTrans is used to store the color transformation information which the setTransform method will use to apply the color fade based on the current ratio.

for(var i in this.v.change){ newTrans[i] = this.v.startTrans[i]+ratio*this.v.change[i];}

This for loop goes through all the properties of the Change color trans obj (remember the Change object stores the difference in values between the goaltTrans obj and the startTrans object so if goalTrans.ra=60 and startTrans.ra=50 then change.ra=10) and multiplies the values in the change object by the ratio and adds that value to the startTrans object. If startTrans.ra=50, change.ra=10 and ratio=.5 then newTrans.ra will equal 50+(10*.5) which equals 55.

this.setTransform(newTrans);

Now that you know the color transformation which lies between the goalTrans and the startTrans, apply it to the target of the color object so it actually changes colors.

}else{

This next code block will only be executed if the color fade is complete.

this.setTransform(this.v.goalTrans);

Set the target of the Color object to it's final destination color.

clearInterval(this.v.intrvl);

Since we have arrived at the destination color there's no need to do anymore fading. Clearinterval removes the function we're currently working with from setinterval's list of functions to execute.

var myFunc = this.v.func;

Stores a reference to the function which is supposed to execute when the color fade is finished as a local variable. We store it as a local variable because we are about to remove the "V"ariable object which stores its current reference.

delete(this.v);

Removes ALL the variables which were stored in the "V"ariable object and the "V"ariable object itself. This also lets the fadeTrans function know that the color fade is complete and that there is no color fade currently taking place.

if(myFunc)myFunc();

Now that everything is all buttoned up call the function specified in the func argument of the fadeTrans function.

So far so good. We now have all the functions we need to complete a color fade from one transformation object to the next, everything else is just gravy.