# Changing Color (colour) using ActionScript Buttons

**URL:** https://forum.kirupa.com/t/changing-color-colour-using-actionscript-buttons/148389
**Category:** Uncategorized
**Created:** [May 19, 2005, 2:38pm UTC](https://forum.kirupa.com/t/changing-color-colour-using-actionscript-buttons/148389 "2005-05-19T14:38:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jues](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jues](https://forum.kirupa.com/u/jues)
#### Post date: [May 19, 2005, 2:38pm UTC](https://forum.kirupa.com/t/changing-color-colour-using-actionscript-buttons/148389/1 "2005-05-19T14:38:07Z")

</div>

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:

```auto

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]
