PDA

View Full Version : Tweening (not simply changing) Color via actionscript


dwayneneckles
08-21-2004, 11:58 PM
Hello,

Lets say I have a graphic and I set it with a color of yellor using the colortransform.....

var my_color:Color = new Color(this.my_mc);
var myColorTransform:Object = {ra:50 , rb:244, ga: 40, gb: 112, ba: 12, bb: 90, aa: 100, ab: 0 }
this.my_color.setTransform(this.myColorTransform);


what if i wanted the color to fade in.....
I didnt know how to do change using the onEnterframe to visually reduce the opacity of the color so that the original graphic comes through

i tried doing simply this,

this.onEnterframe = function() {
this.myColorTransform.ab--;
this.my_color.setTransform(this.myColorTransform);
if (this.myColorTransform.ab == -100)
}
}

but it doesnt work... any can tell me why? :confused:

madgett
08-22-2004, 12:35 AM
The speed of the fade in will work only depending on the frame rate of the stage. I tested this at 12 fps and it works great.


var my_color:Color = new Color(my_mc);
var cra:Number = 0;
var crb:Number = 0;
var cga:Number = 0;
var cgb:Number = 0;
var cba:Number = 0;
var cbb:Number = 0;
var caa:Number = 0;
var cab:Number = 0;
function colorTransform(a:Number, b:Number, c:Number, d:Number, e:Number, f:Number, g:Number, h:Number) {
if (cra<a) {
++cra;
}
if (crb<b) {
++crb;
}
if (cga<c) {
++cga;
}
if (cgb<d) {
++cgb;
}
if (cba<e) {
++cba;
}
if (cbb<f) {
++cbb;
}
if (caa<g) {
++caa;
}
if (cab<h) {
++cab;
}
else if (cra==a && crb==b && cga==c && cgb==d && cba==e && cbb==f && caa==g && cab==h) {
trace("onEnterFrame deleted");
delete this.onEnterFrame;
}
var myColorTransform:Object = {ra:cra, rb:crb, ga:cga, gb:cgb, ba:cba, bb:cbb, aa:caa, ab:cab};
my_color.setTransform(myColorTransform);
}
onEnterFrame = function() {
colorTransform(50, 244, 40, 112, 12, 90, 100, 0); // all you have to do is change these numbers here
//colorTransform(ra, rb, ga, gb, ba, bb, aa, ab)
// Follow the format above
checkNumbers();
}
function checkNumbers() { // For testing purposes
trace(cra+" "+crb+" "+cga+" "+cgb+" "+cba+" "+cbb+" "+caa+" "+cab);
}