Use the beginGradientFill( ) and endFill( ) methods to initiate and close a shape drawn at runtime. 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 colors alphas ratios matrix
Here is an example that uses a linear gradient to fill a rectangle: // Include the drawing methods, which are needed for the drawRectangle( ) method. #include "DrawingMethods.as" // Define the width and height of the rectangle to be drawn and filled. rectWidth = 100; rectHeight = 200; // Create an empty clip into which we will draw the shape.
_root.createEmptyMovieClip("shape_mc", 1);
shape_mc.lineStyle(3, 0, 100);
// Create a colors array with RGB values for blue, green, and red. colors = [0x0000FF, 0x00FF00, 0xFF0000]; // Create an alphas array in which the colors are 100% opaque. alphas = [100, 100, 100]; // Create a ratios array where pure blue is at the left edge of the gradient, pure // green is in the center, and pure red at the right edge. ratios = [0, 127.5, 255]; // Create the matrix object. Set the x and y coordinates so that the bottom-left
// corner of the gradient lines up with the bottom-left corner of the rectangle. Set
// the width and height of the gradient to match the rectangle.
matrix = {matrixType: "box", x: -rectWidth/2, y: -rectHeight/2, w: rectWidth,
h: rectHeight, r:0};
// Call beginGradientFill( ) so that the rectangle will be
// filled with a linear gradient.
shape_mc.beginGradientFill("linear", colors, alphas, ratios, matrix);
// Draw the rectangle with rounded corners (requires DrawingMethods.as). shape_mc.drawRectangle(rectHeight, rectWidth, 10); // End the fill. shape_mc.endFill( ); Note that the endFill( ) method is used to end a drawing operation begun with either beginFill( ) or beginGradientFill( ). Here is an example of a radial, gradient fill used to fill an ellipse: // Include the drawing methods, which are needed for the drawEllipse( ) method. #include "DrawingMethods.as" // Define the width and height of the ellipse to be drawn and filled. ellipseWidth = 100; ellipseHeight = 200; _root.createEmptyMovieClip("shape_mc", 1);
shape_mc.lineStyle(3, 0x000000, 100);
// Create colors, alphas, and ratios arrays for white and black, both 100% opaque. // Pure white starts in the center and grades into pure black at the outside edge. colors = [0xFFFFFF, 0x000000]; alphas = [100, 100]; ratios = [0, 255]; // Define the matrix object.
matrix = {matrixType: "box", x: -ellipseWidth/2, y: -ellipseHeight/2,
w: ellipseWidth, h: ellipseHeight, r:0};
// Begin the radial fill.
shape_mc.beginGradientFill("radial", colors, alphas, ratios, matrix);
// Draw the ellipse (requires DrawingMethods.as). shape_mc.drawEllipse(ellipseWidth/2, ellipseHeight/2); // End the fill. shape_mc.endFill( );
|
|||||||||||||
Disclaimer
1) E-articles is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringement, please read the terms of service and contact us or use the "Report this article" button on this page to investigate the problem.
2) E-articles is not responsible for inaccuracies, falsehoods, or any other types of misinformation this article may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here. |
|||||||||||||