View comments | RSS feed

MovieClip.beginGradientFill()

Availability

Flash Player 6.

Usage

my_mc.beginGradientFill(fillType:String, colors:Array, alphas:Array, ratios:Array, matrix:Object) : Void

Parameter

fillType Either the string "linear" or the string "radial".

colors An array of RGB hex color values to be used in the gradient (for example, red is 0xFF0000, blue is 0x0000FF, and so on).

alphas An array of alpha values for the corresponding colors in the colors array; valid values are 0-100. If the value is less than 0, Flash uses 0. If the value is greater than 100, Flash uses 100.

ratios An array of color distribution ratios; valid values are 0-255. This value defines the percentage of the width where the color is sampled at 100 percent.

matrix A transformation matrix that is an object with either of the following two sets of properties.

If a matrixType property exists then it must equal "box" and the remaining parameters are all required. The function fails if any of these conditions are not met.



Returns

Nothing.

Description

Method; indicates the beginning of a new drawing path. If the first parameter is undefined, or if no parameters are passed, the path has no fill. If an open path exists (that is if the current drawing position does not equal the previous position specified in a MovieClip.moveTo() method), and it has a fill associated with it, that path is closed with a line and then filled. This is similar to what happens when you call MovieClip.endFill().

This method fails if any of the following conditions exist:

You can extend the methods and event handlers of the MovieClip class by creating a subclass. For more information, see "Assigning a class to a movie clip symbol" in Using ActionScript in Flash.

Example

The following code uses both methods to draw two stacked rectangles with a red-blue gradient fill and a 5-pixel solid lime green stroke:

this.createEmptyMovieClip("gradient_mc", 1);
with (gradient_mc) {
   colors = [0xFF0000, 0x0000FF];
   alphas = [100, 100];
   ratios = [0, 0xFF];
   lineStyle(5, 0x00ff00);
   matrix = {a:500, b:0, c:0, d:0, e:200, f:0, g:350, h:200, i:1};
   beginGradientFill("linear", colors, alphas, ratios, matrix);
   moveTo(100, 100);
   lineTo(100, 300);
   lineTo(600, 300);
   lineTo(600, 100);
   lineTo(100, 100);
   endFill();
   matrix = {matrixType:"box", x:100, y:310, w:500, h:200, r:(0/180)*Math.PI};
   beginGradientFill("linear", colors, alphas, ratios, matrix);
   moveTo(100, 310);
   lineTo(100, 510);
   lineTo(600, 510);
   lineTo(600, 310);
   lineTo(100, 310);
   endFill();
}



See also

MovieClip.beginFill(), MovieClip.endFill(), MovieClip.lineStyle(), MovieClip.lineTo(), MovieClip.moveTo()

Comments


ColemanTO said on Mar 9, 2005 at 1:43 PM :
Is it possible to create a gradient that has more than two colors, i.e.: red to yellow to green? I can set multiple colors in a gradient with the color mixer, and I want to acheive the same effect with Actionscript.
ColemanTO said on Mar 10, 2005 at 7:05 AM :
Answering my own question, this works:

this.createEmptyMovieClip("gradient_mc", 1);
with (gradient_mc) {
colors = [0xFF0000, 0xFFFF00, 0x00FF00];
alphas = [100, 100, 100];
ratios = [0, 125, 255];
matrix = {matrixType:"box", x:100, y:100, w:200, h:200, r:(135/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(100, 100);
lineTo(100, 300);
lineTo(300, 300);
lineTo(300, 100);
lineTo(100, 100);
endFill();
}
No screen name said on May 22, 2005 at 5:42 AM :
Is it possible to create a gradient that would (horinzontaly r=1.57) go from one color fade to white in the middle and back to the same color on the opposite edge?
No screen name said on Apr 20, 2006 at 4:48 AM :
Answering to ColemanTO's question - one gradient can only have maximum 8 colors. Color mixer does have the same limitation!

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001489.html