I was trying to find out how to enable themes for display objects with gradient fills. Essentially I had to apply a gradient with the two colors provided at run time. The user could make use of a color picker to pick two colors of his choice and the entire display list elements that correspond to a particular type(say Button) would have the colortransform object applied to reflect a new gradient. This is how i got it done…
Create a movieclip with gradient fill starting at 0x000000(black) and ending with 0xFFFFFF(white). The code that applies a new gradient to replace the black to white is given below.
var clr1:uint = 0x660000;//color replacement for 0x000000
var clr2:uint = 0x333300;//color replacement for 0xFFFFFF
//calculating parameters for ColorTransform constructor
var ro:Number = (clr1 & 0xFF0000)>>16;//red offset for ColorTransform constructor
var rm:Number = (((clr2 & 0xFF0000)>>16)-ro)/255;//red multiplier for ColorTransform constructor
var go:Number = (clr1 & 0x00FF00)>>8;//green offset for ColorTransform constructor
var gm:Number = (((clr2 & 0x00FF00)>>8)-go)/255;//green multiplier for ColorTransform constructor
var bo:Number= (clr1 & 0x0000FF);//blue offset for ColorTransform constructor
var bm:Number = ((clr2 & 0x0000FF)-bo)/255;//blue multiplier for ColorTransform constructor
var clrtransform:ColorTransform = new ColorTransform(rm, gm, bm, 0, ro, go, bo, 255);//ColorTransform Constructor
Find the attachment to see it working.
Hope it might be of help to someone.
Regards