Change a Color

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:

btnBlue.addEventListener(MouseEvent.CLICK,changeColor);
btnRed.addEventListener(MouseEvent.CLICK,changeColor);
btnYellow.addEventListener(MouseEvent.CLICK,changeColor);
btnPurple.addEventListener(MouseEvent.CLICK,changeColor);
function changeColor(e:MouseEvent):void {
   var colorT:ColorTransform = new ColorTransform();
   switch(e.target.name) {  //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
INDEX, Change the Color: ColorTransform, Prepare a Flower for changing petal color, Change the color of the Flower, Color Picker Component, Pick Color with ColorPicker Component, A Random Color, A Random Color with a lighter and darker shading, Shading the Flower with a ColorPicker, Random Shades of a Color
Next lesson: Components

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Change the Color: ColorTransform