How to apply GRADIENT fill using ActionScript

I was wondering if abybody knows how to apply gradient fill using ActionScript (I need to change it when some event accrues).
Is it possible at all?

are you trying to apply it dynamically? or you just want to change from one gradient to another.

Like it is possible to do with setRGB function to set up a color for the plain fill. I thought there could be some possibility to give a name to a gradient swatch to use it in AS

It is possible, but I don’t think you want to mess with that. I know Supra is gonna come and say that it’s not so hard, but it is.
Basically, what I understood is that you have to handle them with a matrix. I found an example for a linear gradient in a square, positionned at (100,100) and 200 pixels wide.

 _root.createEmptyMovieClip( "grad", 1 );  // our mc
 with ( _root.grad )
 	colors = [ 0xFF0000, 0x0000FF , 0xFF00 , 0xFF00FF ];
 	// from red to blue to green to purple
 	alphas = [ 100, 100 , 100 , 100 ];
 	// alpha 100 for every color
 	ratios = [ 0, 0x55 , 0xAA , 0xFF ];
 	// they represent a percentage :
 	// the color is at its max when you get to
 	// ratios[n]% of the width of the fill, except it's
 	// not a per100age but a per255age
 	// That's why you have to put the values in hexadecimal

 	matrix = { matrixType:"box", x:100, y:100, w:200, h:200, r: Math.PI/2 };
 	// we want a simple matrix, we indicate its origin,
 	// width, height and rotation (90 degrees)
 	// Then we draw the rectangle
 	beginGradientFill( "linear", colors, alphas, ratios, matrix );

This code belongs to Supersatori from

I hope this helps.

pom :asian:

To become the king of the matrix, it’s there :