felipegm
November 17th, 2004, 07:40 AM
HI,
I followed this tutorial (http://www.kirupa.com/developer/actionscript/color.htm) , but Iīd like to add something more but donīt know how.
I[d like to make the MC to load a random color, in a color range that I specify, like #000000, #FFFFFF and #111111.
Also, I want somew buttons to change between this colors, but with an ease transition.
How can I do this?
sky_vault
November 18th, 2004, 04:27 AM
This is how I do AS color fades on movie clips ... maybe someone else
can help with setting random colors ... hope this helps.
Timeline :
MovieClip.prototype.fadeColor = function(finalColor, finalAlpha, speed) {
this.percentage = 0;
clearInterval(this.fadeInt);
this.tmpColor = new Color(this);
this.deltaAlpha = finalAlpha-this._alpha;
this.startAlpha = this._alpha;
this.fade = function(target_MC) {
if (target_MC.percentage>=1) {
target_MC.startColor = finalColor;
target_MC._alpha = finalAlpha;
clearInterval(target_MC.fadeInt);
} else {
target_MC.percentage += speed;
target_MC.tmpColor.blendRGB(target_MC.startColor, finalColor, target_MC.percentage);
if (target_MC.deltaAlpha != 0) {
target_MC._alpha = target_MC.startAlpha+(target_MC.deltaAlpha*target_ MC.percentage);
}
}
};
this.fadeInt = setInterval(this.fade, 40, this);
};
ASSetPropFlags(MovieClip.prototype, "fadeColor", 1, 0);
Color.prototype.blendRGB = function(c1, c2, t) {
if (arguments.length == 2) {
t = c2;
c2 = this.getRGB();
}
if (t<-1) {
t = -1;
} else if (t>1) {
t = 1;
}
if (t<0) {
t = 1+t;
}
c1 = c1.HEXtoRGB();
c2 = c2.HEXtoRGB();
var ct = (c1.rb+(c2.rb-c1.rb)*t) << 16 | (c1.gb+(c2.gb-c1.gb)*t) << 8 | (c1.bb+(c2.bb-c1.bb)*t);
this.setRGB(ct);
return ct;
};
// RGB to Hex
// convert
Number.prototype.HEXtoRGB = function() {
return {rb:this >> 16, gb:(this >> 8) & 0xff, bb:this & 0xff};
};
button code:
on (release){
fadeColor(0xE794BD, 40, .05);
}
MovieClip :this sets the function on the clip 0% alpha is a work around
I use a control clip after initial load to fade up clips
onClipEvent (load){
fadeColor(0xCCCC33, 0, .05);
}
control clip:
onClipEvent (load){
fadeColor(0xCCCC33, 40, .05);
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.