If we want to shade the flower when we select a color with the color picker, we must break the value of the color into the red, green and blue values, then create the shades as before. The code is shown below:
var light,medium,dark:int; //3 shades of the same color
colorPicker.addEventListener(Event.CHANGE,pickColor);
function pickColor(e:Event):void {
var colorT:ColorTransform = new ColorTransform();
setShades();
colorT.color = light;
flower.lightArea.transform.colorTransform = colorT; //change the color of the box
colorT.color = medium;
flower.colorArea.transform.colorTransform = colorT; //change the color of the box
colorT.color = dark;
flower.darkArea.transform.colorTransform = colorT; //change the color of the box
} //changeColor
function setShades(): void {
medium=colorPicker.selectedColor;
var color:int=colorPicker.selectedColor;
var red,green,blue:int;
blue=color%256;
color=color/256;
green=color%256;
red=color/256;
var darkRed:int=red*0.6;
var darkGreen:int=green*0.6;
var darkBlue:int=blue*0.6;
dark=(darkRed*256*256)+(darkGreen*256)+darkBlue; //RGB value
//notice the difference in setting ltRed,ltGreen and ltBlue. The result is the same
var ltRed:int=red*1.5;
if(ltRed>255) ltRed=255;
var ltGreen:int=green*1.5;
ltGreen=Math.min(ltGreen,255);
var ltBlue:int=Math.min(blue*1.5,255);
light=(ltRed*256*256)+(ltGreen*256)+ltBlue; //RGB value
} //randomColor
Download movie