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.