Actionscript for tweening advanced color settings?
Hello!
Is it possible to use actionscript to tween the advanced color settings in a movieclip? I'd like to tween a picture from 0 to 255 (R, G, B, A) and then back to normal. I can do this using the timeline, but I would love to learn how to do with with actionscript instead.
I'll attach an example to this posting of the effect I'm trying to create.
Ahh.... venerable photo flash effect. I love it. I use a lot myself. Anyway you can accomplish this using the onEnterFrame function. Which uses time base iteration ( loops ) as oppossed to processor baser iterators ( for...I, do...while, etc ). I'm not sure if you are familiar with the onEnterFrame function but I will post the code in the next couple of minutes that accomplishes what you need.
This function would whiten the picture movieclip then go back to normal. You'll find out that sometimes, frame based tweens are simpler ;)
PHP Code:
function recolor(t, r, c) {
done=false;
var o = new Color(t).getTransform();
t.onEnterFrame = function() {
col = new Color(this);
col.setTransform(o);
if (--r) {
for (var i in c) {
o[i] += (c[i]-o[i])/r;
}
} else {
done=true;
delete t.onEnterFrame;
}
};
}
recolor(a1, 24, {rb:180, bb:170,gb:160});
this.onEnterFrame = function() {
if (done) {
recolor(a1, 24, {rb:0, bb:0,gb:0});
done=false;
delete this.onEnterFrame;
}
};
In the function call recolor(a1, 24, {rb:0, bb:0,gb:0})
the picture movieclip instance name is: 'a1'
the rate, which can be modifed is '24'
and the rb, bb and gb vars are the rgb values.
You make a separate function for the alpha. And in that function you call the fadeColor(parameters) function. As the fade in function is called first, you may want to set the variables in it. Then check for the moment when _alpha is almost at 100.
Something like:
code:
if (pic._alpha>99) {
fadeColor(params);
} else {
pic._alpha+=5; // fade in
}
small recap. Events in that order:
call the fade in function:
- set _alpha to zero
- set color of image to white: colorObject.setTransform({rb:255, bb:255, gb:255});
use the if statement and call the fadeColor function: to turn gb,bb and rb to 0.
Thanks! I think I'm getting closer but need some more help! I tried incorporating your code into the code I posted, and I think I added them in the right place, but it doesn't work? Also, could you give me an example of what is found in the (parameter) parentheses? Thanks so much for your help!
Code:
var cColor;
MovieClip.prototype.fadeColor = function(cto, ease) {
var d = 0;
var myColor = new Color(this);
// myColor.setTransform({ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:0});
this.onEnterFrame = function() {
for (var c in cColor) {
cColor[c] += (cto[c]-cColor[c])/ease;
}
myColor.setTransform(cColor);
d++;
if (d>20) {
if (pic._alpha>99) {
fadeColor(params);
} else {
pic._alpha+=5; // fade in
}
cto = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, aa:100, ab:0};
ease = 10;
}
};
};
pic.fadeColor({ra:100, rb:255, ga:100, gb:255, ba:100, bb:255, aa:100, ab:0}, 5);
var myColor = new Color(pic);
cColor = myColor.getTransform();
Last edited by sirenetta1; 07-29-2005 at 09:15 AM.
Guess i was not clear enough. this is what should happen:
Fade in function:
set image alpha to 0
set image color to white: set the rb, gb and bb variables to 255.
start a loop (enterFrame)
check if it’s bigger than 99
if yes: call the debrightening function
else: make the alpha go up
debrightening function:
start a loop (enterFrame)
bring the rb, gb and bb variables back to 0.
when they are delete the enterFrame.
Dang! And I actually thought I was doing something with it. Honestly, I am new to this so it's difficult for me!! But, I'm sure it gives you some smiles.
Let's see... I guess it didn't work... Should I rather place the alpha code on the movie clip or should it be in with this code?