4.10. Filling a Shape with a Gradient
Problem
You want to draw a shape and fill it with a gradient at runtime.
Solution
Use the beginGradientFill( ) and
endFill( ) methods to initiate and close a shape
drawn at runtime.
Discussion
In a gradient fill, there is a graded change in
colors. Flash supports linear gradients, in which one color fades
into the next from left to right. Flash also supports radial
gradients, in which the colors radiate out from a center point. You
can initiate a gradient-filled shape using
beginGradientFill( ) in
the same way you initiate a solid-filled
shape with beginFill( ). The difference is that
the call to beginGradientFill( ) requires a more
complex set of parameters:
-
gradientType Either “linear” for a linear gradient, or “radial” for a radial gradient.
-
colors An array of RGB values for the colors to use in the gradient. They are displayed in the gradient from left to right in a linear gradient, or from the center outward in a radial gradient.
-
alphas An array of alpha values that correspond to the colors in the
colorsparameter array.-
ratios An array whose elements are numbers corresponding to the
colorsandalphaselements. The values in theratiosarray indicate the point within the gradient at which each color is pure. The range of values for theratiosshould be from 0 (leftmost point in a linear fill, or innermost point in a radial fill) to 255 (rightmost or outermost).-
matrix An object with the following properties:
-
matrixType This value should ...
-
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access