Changing a Color in ActionScript

Get Adobe Flash player

The flower movie clip contains a movie clip called colorArea that is just the fill from the petals. 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
   flower.colorArea.transform.colorTransform = colorT; //change the color of the box
} //changeColororTransform = colorT; //change the color of the box
} //changeColor
Download movie

NEXT: Color Picker Component