Adobe® Flex® 4 Language Reference
Hide Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
flash.display 
GraphicsGradientFill 
Packageflash.display
Classpublic final class GraphicsGradientFill
InheritanceGraphicsGradientFill Inheritance Object
Implements IGraphicsFill, IGraphicsData

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

Defines a gradient fill.

Use a GraphicsGradientFill object with the Graphics.drawGraphicsData() method. Drawing a GraphicsGradientFill object is the equivalent of calling the Graphics.beginGradientFill() method.

See also



Public Properties
 PropertyDefined By
  alphas : Array
An array of alpha values for the corresponding colors in the colors array.
GraphicsGradientFill
  colors : Array
An array of RGB hexadecimal color values to use in the gradient.
GraphicsGradientFill
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  focalPointRatio : Number
A number that controls the location of the focal point of the gradient.
GraphicsGradientFill
  interpolationMethod : String
A value from the InterpolationMethod class that specifies which value to use.
GraphicsGradientFill
  matrix : Matrix
A transformation matrix as defined by the Matrix class.
GraphicsGradientFill
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
  ratios : Array
An array of color distribution ratios.
GraphicsGradientFill
  spreadMethod : String
A value from the SpreadMethod class that specifies which spread method to use.
GraphicsGradientFill
  type : String
A value from the GradientType class that specifies which gradient type to use.
GraphicsGradientFill
Public Methods
 MethodDefined By
  
GraphicsGradientFill(type:String = "linear", colors:Array = null, alphas:Array = null, ratios:Array = null, matrix:* = null, spreadMethod:* = pad, interpolationMethod:String = "rgb", focalPointRatio:Number = 0.0)
Creates a new GraphicsGradientFill object.
GraphicsGradientFill
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
Property Detail

alphas

property
public var alphas:Array

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

An array of alpha values for the corresponding colors in the colors array. Valid values are between 0 and 1. If the value is less than 0, 0 is used. If the value is greater than 1, 1 is used.

colors

property 
public var colors:Array

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

An array of RGB hexadecimal color values to use in the gradient. For example, red is 0xFF0000, blue is 0x0000FF, and so on. You can specify up to 15 colors. For each color, specify a corresponding value in the alphas and ratios properties.

focalPointRatio

property 
public var focalPointRatio:Number

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

A number that controls the location of the focal point of the gradient. A value of 0 sets the focal point in the center. A value of 1 means that the focal point is at one border of the gradient circle.A value of -1 sets the focal point at the other border of the gradient circle. A value of less than -1 or greater than 1 is rounded to -1 or 1, respectively. For example, the following shows a focalPointRatio set to 0.75:

radial gradient with focalPointRatio set to 0.75

interpolationMethod

property 
interpolationMethod:String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

A value from the InterpolationMethod class that specifies which value to use. Valid values are: InterpolationMethod.LINEAR_RGB or InterpolationMethod.RGB

For example, the following shows a simple linear gradient between two colors (with the spreadMethod parameter set to SpreadMethod.REFLECT). The different interpolation methods change the appearance as follows:

linear gradient with InterpolationMethod.LINEAR_RGB linear gradient with InterpolationMethod.RGB
InterpolationMethod.LINEAR_RGBInterpolationMethod.RGB



Implementation
    public function get interpolationMethod():String
    public function set interpolationMethod(value:String):void

See also

matrix

property 
public var matrix:Matrix

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

A transformation matrix as defined by the Matrix class. The flash.geom.Matrix class includes a createGradientBox() method to set up the matrix for use with the beginGradientFill() method.

See also

ratios

property 
public var ratios:Array

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

An array of color distribution ratios. Valid values are between 0 and 255. This value defines the percentage of the width where the color is sampled at 100%. The value 0 represents the left position in the gradient box, and the value 255 represents the right position in the gradient box.

Note: This value represents positions in the gradient box, not the coordinate space of the final gradient which can be wider or thinner than the gradient box. Specify a value for corresponding to each value in the colors property.

For example, for a linear gradient that includes two colors (blue and green) the following example illustrates the placement of the colors in the gradient based on different values in the ratios array:

ratiosGradient
[0, 127]linear gradient blue to green with ratios 0 and 127
[0, 255]linear gradient blue to green with ratios 0 and 255
[127, 255]linear gradient blue to green with ratios 127 and 255

The values in the array must increase sequentially; for example, [0, 63, 127, 190, 255].

spreadMethod

property 
spreadMethod:String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

A value from the SpreadMethod class that specifies which spread method to use. Valid values are: SpreadMethod.PAD, SpreadMethod.REFLECT, or SpreadMethod.REPEAT.

For example, the following shows a simple linear gradient between two colors:

     import flash.geom.*
     import flash.display.*
     var fillType:String = GradientType.LINEAR;
     var colors:Array = [0xFF0000, 0x0000FF];
     var alphas:Array = [1, 1];
     var ratios:Array = [0x00, 0xFF];
     var matr:Matrix = new Matrix();
     matr.createGradientBox(20, 20, 0, 0, 0);
     var spreadMethod:String = SpreadMethod.PAD;
     this.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);       
     this.graphics.drawRect(0,0,100,100);
     

This example uses SpreadMethod.PAD for the spread method, and the gradient fill looks like the following:

linear gradient with SpreadMethod.PAD

If you use SpreadMethod.REFLECT for the spread method, the gradient fill looks like the following:

linear gradient with SpreadMethod.REFLECT

If you use SpreadMethod.REPEAT for the spread method, the gradient fill looks like the following:

linear gradient with SpreadMethod.REPEAT



Implementation
    public function get spreadMethod():String
    public function set spreadMethod(value:String):void

See also

type

property 
type:String

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

A value from the GradientType class that specifies which gradient type to use. Values are GradientType.LINEAR or GradientType.RADIAL.



Implementation
    public function get type():String
    public function set type(value:String):void

See also

Constructor Detail

GraphicsGradientFill

()Constructor
public function GraphicsGradientFill(type:String = "linear", colors:Array = null, alphas:Array = null, ratios:Array = null, matrix:* = null, spreadMethod:* = pad, interpolationMethod:String = "rgb", focalPointRatio:Number = 0.0)

Language Version: ActionScript 3.0
Runtime Versions: Flash Player 10, AIR 1.5

Creates a new GraphicsGradientFill object.

Parameters
type:String (default = "linear") — A value from the GradientType class that specifies which gradient type to use: GradientType.LINEAR or GradientType.RADIAL.
 
colors:Array (default = null) — An array of RGB hexadecimal color values used in the gradient; for example, red is 0xFF0000, blue is 0x0000FF, and so on. You can specify up to 15 colors. For each color, specify a corresponding value in the alphas and ratios parameters.
 
alphas:Array (default = null) — An array of alpha values for the corresponding colors in the colors array; valid values are 0 to 1. If the value is less than 0, 0 is used. If the value is greater than 1, 1 is used.
 
ratios:Array (default = null) — 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%. The value 0 represents the left position in the gradient box, and 255 represents the right position in the gradient box.
 
matrix:* (default = null) — A transformation matrix as defined by the flash.geom.Matrix class. The flash.geom.Matrix class includes a createGradientBox() method, which lets you conveniently set up the matrix for use with the beginGradientFill() method.
 
spreadMethod:* (default = pad) — A value from the SpreadMethod class that specifies which spread method to use, either: SpreadMethod.PAD, SpreadMethod.REFLECT, or SpreadMethod.REPEAT.
 
interpolationMethod:String (default = "rgb") — A value from the InterpolationMethod class that specifies which value to use: InterpolationMethod.LINEAR_RGB or InterpolationMethod.RGB
 
focalPointRatio:Number (default = 0.0) — A number that controls the location of the focal point of the gradient. A value of 0 sets the focal point in the center. A value of 1 sets the focal point at one border of the gradient circle. A value of -1 sets the focal point at the other border of the gradient circle. A value less than -1 or greater than 1 is rounded to -1 or 1, respectively.

See also