Changing a Color in ActionScript

You will learn to use a ColorTransform object to change the color of a movie clip.

The colors are RGB values coded as hexadecimal numbers. If you are not familiar with RGB colors please read the explanation.

Select a color for the box:
Get Adobe Flash player

The box is a movie clip named box. The buttons are named btnBlue, bthRed, btnYellow and btnPurple.

The code is shown below:

function changeColor(e:MouseEvent):void {
   var colorT:ColorTransform = new ColorTransform();
   switch( {  //which button was clicked?
      case "btnBlue": colorT.color=0x0000FF; break; //blue in hexadecimal
      case "btnRed": colorT.color=0xFF0000; break; //red in hexadecimal
      case "btnYellow": colorT.color=0xFFFF00; break; //yellow in hexadecimal
      case "btnPurple": colorT.color=0xFF00FF; break; //purple in hexadecimal
   } //switch
   box.transform.colorTransform = colorT; //change the color of the box
} //changeColor
Download movie

NEXT: Prepare a Flower for changing petal color