PDA

View Full Version : fmx color protos



jagunco
October 18th, 2003, 08:03 AM
Hello to all

does someone knows how to fade between two color, or better, to change a color of an mc to another but smootlhy. I canīt find any proto about this.

thsnks

Voetsjoeba
October 18th, 2003, 08:54 AM
Here's one I quickly created:



MovieClip.prototype.changeColour = function(cObject, r, g, b, a) {
var tC = [r, g, b, a];
var speed = 1.2;
this.temp.removeMovieClip();
this.createEmptyMovieClip("temp", 1);
this.temp.onEnterFrame = function() {
pC = [cObject.getTransform().ra, cObject.getTransform().ga, cObject.getTransform().ba, cObject.getTransform().aa];
if (pC[0]==tC[0] && pC[1]==tC[1] && pC[2]==tC[2]) {
this.removeMovieClip();
} else {
cObject.setTransform({ra:tC[0]-(tC[0]-pC[0])/speed, ga:tC[1]-(tC[1]-pC[1])/speed, ba:tC[2]-(tC[2]-pC[2])/speed, aa:tC[3]-(tC[3]-pC[3])/speed});
}
updateAfterEvent();
};
};
// Usage:
box.onRelease = function() {
this.changeColour(new Color(this), 50, 25, 75, 60);
};

jagunco
October 18th, 2003, 11:17 AM
thanks, but this dosenīt work fine, because , when you set the new color value, what this proto does is mix the colors of the mc whit new one

Voetsjoeba
October 18th, 2003, 11:30 AM
As I said, I created this really quick ... lemme work on a better proto. By the way, go to http://proto.layer51.com for a lot of prototypes :)

jagunco
October 18th, 2003, 11:56 AM
I went there and I didnīt find what Iīm looking
thanks anyway

Voetsjoeba
October 18th, 2003, 12:05 PM
Aha, I just found an experiment from a while ago using color easing. Now all I gotta do is prototype-alize it.

jagunco
October 18th, 2003, 12:24 PM
when you finish it, if you donīt mind send me, please.

thanks

Voetsjoeba
October 18th, 2003, 02:05 PM
Ok, I found why the colours aren't pure. It seems like setTransform of a colour object works like a movieclip's tint. So if your box isn't white, your colour can't be pure. This is a better version of the prototype (well, at least it should be :P)



MovieClip.prototype.setColor = function(r, g, b, a) {
var c = new Color(this);
var tV = [r, g, b, a];
var speed = 1.2;
var margin = 4
this.onEnterFrame = function() {
cV = [c.getTransform().ra, c.getTransform().ga, c.getTransform().ba, c.getTransform().aa];
change = {ra:tV[0]-(tV[0]-cV[0])/speed, ga:tV[1]-(tV[1]-cV[1])/speed, ba:tV[2]-(tV[2]-cV[2])/speed, aa:tV[3]-(tV[3]-cV[3])/speed};
c.setTransform(change);
if (cV[0]>tV[0]-margin && cV[0]<tV[0]+margin && cV[1]>tV[1]-margin && cV[1]<tV[1]+margin && cV[2]>tV[2]-margin && cV[2]<tV[2]+margin) {
delete this.onEnterFrame;
}
};
};
box.onRelease = function() {
this.setColor(100,0,0,100);
};

jagunco
October 19th, 2003, 07:46 AM
itīs working, tomorrow i will try it on a mac, because some time ago I had one, but on mac it didnīt work.

letīs see
thanks Voetsjoeba

senocular
October 19th, 2003, 10:08 AM
Originally posted by jagunco
I went there and I didnīt find what Iīm looking
thanks anyway


:scream: Thats like the 4th time Ive heard someone say that!


Does "Blend" not mean anything to anyone? BlendRGB - BlendColor .... even with example code of blending colors!

BAH! Thats it, Im putting up a fla

jagunco
October 19th, 2003, 10:49 AM
Iīm so sorry senocular

jagunco
October 19th, 2003, 10:55 AM
Senocular, i found your proto, but I need a smooth blend, like a transition.

:)

senocular
October 19th, 2003, 10:57 AM
yeah!
http://proto.layer51.com/d.aspx?f=601

jagunco
October 19th, 2003, 11:07 AM
thanks