Hey guys, sorry to bug you all, but I’m hoping you can help a budding ActionScripter!
I’m trying to make it so when the user clicks a button, it fades from it’s current colour to a pre-defined one… simple enough in theory
Here’s the AS I’ve got so far:
var startColour = {r:50,g:100,b:250};
var endColour = {r:250,g:0,b:120};
function fadeColour(startColour,endColour,t) {
var newR = (endColour.r - startColour.r)*t + startColour.r;
var newG = (endColour.g - startColour.g)*t + startColour.g;
var newB = (endColour.b - startColour.b)*t + startColour.b;
new Colour([color=Red]but01[/color]).setRGB( newR << 16 | newG << 8 | newB );
}
[color=Red]but01[/color].onRelease = function() {
t += 0.1; // Fade Speed
if (t < 1) {
fadeColour(startColour,endColour,t);
} else {
fadeColour(startColour,endColour,1);
}
}
So, let me just walk you thru a few things…
The script works, but not as hoped. The colour will only change when the user is “clicking” on the button, I want to it keep changing colour until it reaches the ‘endColour’ variable (like it should) - I have tried doing an “onRelease” statement, but this didn’t help either
Secondly, like I said in my preamble, I want it to be able to fade from its current colour to a set colour, eg: I need [color=Red]var startColour [color=Black]to be dynamic, rather than fixed, but I don’t know how to read in an objects current colour(!) - any ideas?
Thanks guys.
jonny.
[/color][/color]