# Clear color transform

**URL:** <https://forum.kirupa.com/t/clear-color-transform/98884>\
**Category:** Uncategorized\
**Created:** [January 12, 2004, 4:21pm UTC](https://forum.kirupa.com/t/clear-color-transform/98884 "2004-01-12T16:21:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PixelSense](https://avatars.discourse-cdn.com/v4/letter/p/74df32/32.png) [@PixelSense](https://forum.kirupa.com/u/PixelSense)\
**Post date:** [January 12, 2004, 4:21pm UTC](https://forum.kirupa.com/t/clear-color-transform/98884/1 "2004-01-12T16:21:18Z")

</div>

my animation works… until the part where it fadeClearTrans, it doesn’t work althought it did trace(“yes”)… did i put the function fadeClearTrans(1000) correctly?

[AS]  
//////////////////////////////////////////////////////////////////  
///////////////////// BOXES FADE IN ANIMATION ////////////////////  
//////////////////////////////////////////////////////////////////

fadein = function(alpha, obj, steps) {  
this.alpha = alpha;  
this.obj = obj;  
this.steps = steps; // the lesser steps, the faster the fade  
if (this.obj.\_alpha \>= 100){  
white = new Color(this.obj);  
whiteColor = {ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:0};  
white.setTransform(whiteColor);  
if(white.getRGB().toString(16) == “ffffff”){  
white.fadeClearTrans(1000);  
}  
}  
else{  
this.obj.\_alpha += 100/this.steps;  
}

}

////////////////////////////// END ///////////////////////////////

//////////////////////////////////////////////////////////////////////////////  
//////////////////////////// COLOR FADE FUNCTION /////////////////////////////  
// [actionscript.org/tutorials/advanced/Color\_fade/index.shtml](http://actionscript.org/tutorials/advanced/Color_fade/index.shtml) //  
//////////////////////////////////////////////////////////////////////////////

Math.rgbToHex = function(r, g, b) {  
return ( r \<\< 16 | g \<\< 8 | b );   
}

Math.hextoRGB = function(hex) {  
var red = hex \>\> 16;  
var grnblu = hex - (red \<\< 16);  
var grn = grnblu \>\> 8;  
var blu = grnblu - (grn \<\< 8);  
return ({r:red, g:grn, b:blu});  
}

Color.prototype.transObjSame = function(obj1, obj2) {  
for(var i in obj1){  
if(obj1\* != obj2\*){  
return false;  
}  
}  
return true;  
}

Color.prototype.fadeTransform = function(goalTrans, milSecs, func) {  
if(this.ini){  
if(this.transObjSame(goalTrans, this.ini.goalTrans)){  
trace(“already going there!”);  
return;  
}else{  
clearInterval(this.ini.intrvl);  
}  
}

```
var getTrans = this.getTransform(); // get the current transform state of the mc
if(this.transObjSame(goalTrans, getTrans)){
	trace("Already there!");
	return;
}

this.ini = {};
this.ini.goalTrans = goalTrans;
this.ini.milSec = milSec;
if(typeof func == "function") this.ini.func = func;
this.ini.startTime = getTimer();
this.ini.startTrans = getTrans;

this.ini.change = {};
for(var i in goalTrans){
	this.ini.change* = goalTrans* - this.ini.startTrans*;
}
this.transShift();
if(milSec){
	this.ini.intrvl = setInterval (this, "transShift", 1); 
}

```

}

Color.prototype.transShift = function() {  
ratio = (getTimer()-this.ini.startTime)/this.ini.milSec;  
if(ratio \< 1){  
var newTrans = {};  
for(var i in this.ini.change) {  
newTrans\* = this.ini.startTrans\* + (this.ini.change\* \* ratio);  
}  
this.setTransform(newTrans);  
}else{  
this.setTransform(goalTrans);  
clearInterval(this.ini.intrvl);  
myFunc = this.ini.func;  
delete(this.ini);  
if(myFunc) myFunc();  
}  
}

Color.prototype.fadeClearTrans = function(milSecs, func){  
var goalTrans = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};  
this.fadeTransform(goalTrans, milSecs, func);  
trace(“yes”);  
}

////////////////////////////// END ///////////////////////////////

[/AS]
