ActionScript 3 AS3:创建渐变矩形

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3:创建渐变矩形相关的知识,希望对你有一定的参考价值。

/****************************
Import Classes
****************************/
import flash.display.*;
import flash.geom.*;

/****************************
Define Variables
****************************/
//Type of Gradient we will be using
var fType:String = GradientType.LINEAR;
//Colors of our gradient in the form of an array
var colors:Array = [ 0xF1F1F1, 0x666666 ];
//Store the Alpha Values in the form of an array
var alphas:Array = [ 1, 1 ];
//Array of color distribution ratios.  
//The value defines percentage of the width where the color is sampled at 100%
var ratios:Array = [ 0, 255 ];
//Create a Matrix instance and assign the Gradient Box
var matr:Matrix = new Matrix();
    matr.createGradientBox( 200, 20, 0, 0, 0 );
//SpreadMethod will define how the gradient is spread. Note!!! Flash uses CONSTANTS to represent String literals
var sprMethod:String = SpreadMethod.PAD;
//Start the Gradietn and pass our variables to it
var sprite:Sprite = new Sprite();
//Save typing + increase performance through local reference to a Graphics object
var g:Graphics = sprite.graphics;
    g.beginGradientFill( fType, colors, alphas, ratios, matr, sprMethod );
    g.drawRect( 0, 0, 400, 200 );

addChild( sprite );

以上是关于ActionScript 3 AS3:创建渐变矩形的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 使用AS3绘制一个矩形

ActionScript 3 AS3绘制一个简单的矩形蒙版

通过 AS3 访问(用于导出)在 Flash 编辑器中创建的矩形的渐变

ActionScript 3 AS3创建随机密码

ActionScript 3 AS3:创建一个Bottons网格

ActionScript 3 使用XML创建AS3幻灯片