
Page 7 of 7
Sean O'Shell
This user is yet to take control of their account and provide a biography. If you are the author of this article, please contact us via [email:support@actionscript.org].
View all articles by Sean O'Shell(Usage)
myCO = new Color(SomeImageClip);
Create a Color object to play with and specify which clip it will act upon.
function traceDone(){ trace("DONE FADING!");}
A general function we can execute to show that everything is working.
function fadeRandHex(){
var randHex = Math.floor(Math.random()*0xFFFFFF);
myCO.fadeHex(randHex, Math.floor(Math.random()*1000+100), fadeRandHex)
}
FadeRandHex generates a random hexadecimal representation of a color, fades to that color over a random period of time, then when the color fade is complete fadeRandHex is called again thus repeating the process.
function fadeRandTransform(){
var o = {}; o.ra = Math.floor(Math.random()*200-100);
o.ga = Math.floor(Math.random()*200-100);
o.ba = Math.floor(Math.random()*200-100);
o.rb = Math.floor(Math.random()*512-256);
o.gb = Math.floor(Math.random()*512-256);
o.bb = Math.floor(Math.random()*512-256);
myCO.fadeTransform(o, 3000, fadeRandTransform);
}
FadeRandTransform generates a color transformation object with random values, fades to that randomly generated color trans obj and then when complete fadeRandTransform is called again.
transArray = [];
transArray[0]={ra:-100, rb:255, ga:-100, gb:150, ba:0, bb:0, aa:100, ab:0};
transArray[1]={ra:100, rb:-61, ga:-100, gb:120, ba:-100, bb:255, aa:100, ab:0};
transArray[2]={ra:-100, rb:139, ga:10, gb:0, ba:-100, bb:255, aa:100, ab:0};
transArray[3]={ra:100, rb:255, ga:100, gb:0, ba:-100, bb:255, aa:100, ab:0};
lastTransArray = 0;
function fadeArrayTrans(){
myCO.fadeTransform(transArray[lastTransArray], 2000, fadeArrayTrans)
lastTransArray++; lastTransArray%=transArray.length;
}
This block of code creates an array of four predefined color transformation objects. LastTransArray is used to track which transformation object was last applied. FadeArrayTrans selects a color trans obj from the array, fades to that color trans obj then when complete fadeRandTrans is called again. The lastTransArray variable is incremented and modulated so as to cycle through the objects in the array.
CLEAR.onRelease = function(){
myCO.fadeClearTrans(1000);
}
RED.onRelease = function(){
myCO.fadeRGB(255, 0, 0, 1000, traceDone);
}
ORANGIFY.onRelease = function(){
myCO.fadeTransform(transArray[0], 1000, traceDone);
}
RANDHEX.onRelease = fadeRandHex;
ARRAYTRANS.onRelease = fadeArrayTrans;
RANDTRANS.onRelease = fadeRandTransform;
Spread The Word
Related Articles
1 Response to "Color fade" 
|
said this on 18 Sep 2007 6:37:47 PM CST
One small typo, but it prevents the whole thing from working... The line
this.v.intrvl = setinterval(this, "transShift", 1); Should be this.v.intrvl = setInterval(this, "transShift", 1); |



Author/Admin)