Changing Colors Using ActionScript

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:

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:


// 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!

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

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

:wink:

thanks, aurelius. =)

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. :frowning:

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:

you’re welcome. :wink: