Using complex gradient fills

The Flash Drawing API supports gradient fills as well as solid fills. The following procedure creates a new movie clip on the Stage, use the Drawing API to create a square, and then fills the square with a radial red and blue gradient.

To create a complex gradient:

  1. Create a new Flash document and save it as radialgradient.fla.
  2. Add the following ActionScript to Frame 1 of the Timeline:
    this.createEmptyMovieClip("gradient_mc", 10);
    var fillType:String = "radial";
    var colors:Array = [0xFF0000, 0x0000FF];
    var alphas:Array = [100, 100];
    var ratios:Array = [0, 0xFF];
    var matrix:Object = {a:200, b:0, c:0, d:0, e:200, f:0, g:200, h:200, i:1};
    var spreadMethod:String = "reflect";
    var interpolationMethod:String = "linearRGB";
    var focalPointRatio:Number = 0.9;
    with (gradient_mc) {
        beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod, interpolationMethod, focalPointRatio);
        moveTo(100, 100);
        lineTo(100, 300);
        lineTo(300, 300);
        lineTo(300, 100);
        lineTo(100, 100);
        endFill();
    }
    

    The preceding ActionScript code uses the Drawing API to create a square on the Stage and calls the beginGradientFill() method to fill the square with a red and blue circular gradient.

  3. Save the Flash document and select Control > Test Movie to view the Flash file.

Flash CS3


 

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

Current page: http://livedocs.adobe.com/flash/9.0/main/00000997.html