# Changing Colors Using ActionScript

**URL:** <https://forum.kirupa.com/t/changing-colors-using-actionscript/22080>\
**Category:** Uncategorized\
**Created:** [May 29, 2003, 11:10pm UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080 "2003-05-29T23:10:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paz](https://avatars.discourse-cdn.com/v4/letter/p/22d042/32.png) [@Paz](https://forum.kirupa.com/u/Paz)\
**Post date:** [May 29, 2003, 11:10pm UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/1 "2003-05-29T23:10:25Z")

</div>

Hi I have recently completed the tutorial for the changing colour, by placing my mouse over the button using the following code.

on (rollOver) {  
var colorful = new Color("\_root.shapes");  
colorful.setRGB(0x003366);  
}

I can’t figure out how to make this colour change fade in. Instead of coming in straight away.

I’m open to suggestions!  
Thanks  
:beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 12:09am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/2 "2003-05-30T00:09:17Z")

</div>

If you’re using MX, you can use setInterval() method. If you have a movieclip with an instance of “box\_mc” that contains a colored square (which you can color via the Color.setRGB() object), then use this code to fade it in:

```auto

// create new Color object
var boxColor = new Color("box_mc");

// create a Transform object
var boxTransform = boxColor.getTransform();

var count = 0;
function fadeColorIn() {
    if (count < 100) { // if count is not yet equal to 100
	// set transform properties
	boxTransform.aa = count; // set alpha to count
	count += 1; // count up 1
	// apply the transform properties
	boxColor.setTransform(boxTransform);
  } else {
    // kill the interval from executing
    clearInterval (fadeInterval); 
  } // end if statement
} // end fadeColorIn()

// execute fadeColorIn every 10 milliseconds
var fadeInterval = setInterval(fadeColorIn, 10);

```

This code first creates a new color object (boxColor). Then it creates a generic object (called “boxTransform”) which will contain the alpha properties which will later be applied to the movieclip. In the function fadeColorIn(), the if statement checks whether count has reached 100 or not. If not, it sets the boxTransform property of “aa” (the alpha percentage) equal to the count (which increments each time). If count has reached 100, the setInterval (named “fadeInterval”) is cleared so that it stops executing every 10 milliseconds. Finally, the last line of code starts the interval executing every 10 milliseconds.

Hope this makes sense!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 3:02am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/3 "2003-05-30T03:02:11Z")

</div>

[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=22838](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=22838)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 3:19am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/4 "2003-05-30T03:19:59Z")

</div>

That’s a nice fadeColor method, kax. I like. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 3:30am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/5 "2003-05-30T03:30:44Z")

</div>

😉

thanks, aurelius. =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 8:36am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/6 "2003-05-30T08:36:44Z")

</div>

Thanks aurelius

That was very helpful, but not exactly what I wanted, I think it’s the way I explain things, Im not very good at that. ☹

But I had a look at Kax’s version on the other page and that is just what I wanted it to do. So thanks a lot both of you.

:crazy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 30, 2003, 8:42am UTC](https://forum.kirupa.com/t/changing-colors-using-actionscript/22080/7 "2003-05-30T08:42:21Z")

</div>

you’re welcome. 😉
