| 包 | mx.graphics |
| 类 | public class LinearGradient |
| 继承 | LinearGradient GradientBase EventDispatcher Object |
| 实现 | IFill |
entries Array 中,以定义组成渐变填充的颜色。
在 MXML 中,您可以通过添加一系列 GradientEntry 对象来定义 LinearGradient,如以下示例所示:
<mx:fill>
<mx:LinearGradient>
<mx:entries>
<mx:GradientEntry color="0xC5C551" ratio="0.00" alpha="0.5"/>
<mx:GradientEntry color="0xFEFE24" ratio="0.33" alpha="0.5"/>
<mx:GradientEntry color="0xECEC21" ratio="0.66" alpha="0.5"/>
</mx:entries>
</mx:LinearGradient>
</mx:fill>
在 ActionScript 中,您还可以将 LinearGradient 定义为任何图形元素的填充,如以下示例所示:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
import flash.display.Graphics;
import flash.geom.Rectangle;
import mx.graphics.GradientEntry;
import mx.graphics.LinearGradient;
private function init():void
{
var w:Number = 200;
var h:Number = 200;
var s:Sprite = new Sprite();
// Add the new Sprite to the display list.
rawChildren.addChild(s);
var g:Graphics = s.graphics;
g.lineStyle(1, 0x33CCFF, 1.0);
var fill:LinearGradient = new LinearGradient();
var g1:GradientEntry = new GradientEntry(0xFFCC66, 0.00, 0.5);
var g2:GradientEntry = new GradientEntry(0x000000, 0.33, 0.5);
var g3:GradientEntry = new GradientEntry(0x99FF33, 0.66, 0.5);
fill.entries = [ g1, g2, g3 ];
fill.angle = 240;
// Draw a box and fill it with the LinearGradient.
g.moveTo(0, 0);
fill.begin(g, new Rectangle(0, 0, w, h));
g.lineTo(w, 0);
g.lineTo(w, h);
g.lineTo(0, h);
g.lineTo(0, 0);
fill.end(g);
}
</mx:Script>
</mx:Application>
MXML 语法
隐藏 MXML 语法The <mx:LinearGradient> tag
inherits all the tag attributes of its superclass,
and adds the following tag attributes:
<mx:LinearGradient
Properties
angle="0"
/>
另请参见
| 属性 | 定义方 | ||
|---|---|---|---|
| angle : Number 控制过渡方向。 | LinearGradient | ||
![]() | constructor : Object
对类对象或给定对象实例的构造函数的引用。 | Object | |
![]() | entries : Array GradientEntry 对象 Array,用于定义渐变填充的填充模式。 | GradientBase | |
![]() | prototype : Object [静态]
对类或函数对象的原型对象的引用。 | Object | |
| 方法 | 定义方 | ||
|---|---|---|---|
构造函数。 | LinearGradient | ||
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void 使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。 | EventDispatcher | |
开始填充。 | LinearGradient | ||
![]() | 将事件调度到事件流中。 | EventDispatcher | |
结束填充。 | LinearGradient | ||
![]() | 检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。 | EventDispatcher | |
![]() |
指示对象是否已经定义了指定的属性。 | Object | |
![]() |
指示 Object 类的实例是否在指定为参数的对象的原型链中。 | Object | |
![]() |
指示指定的属性是否存在、是否可枚举。 | Object | |
![]() | 从 EventDispatcher 对象中删除侦听器。 | EventDispatcher | |
![]() |
设置循环操作动态属性的可用性。 | Object | |
![]() |
返回指定对象的字符串表示形式。 | Object | |
![]() |
返回指定对象的原始值。 | Object | |
![]() | 检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。 | EventDispatcher | |
| angle | 属性 |
angle:Number [读写] 控制过渡方向。
默认情况下,LinearGradient 类定义图形元素进行从左到右的过渡。
当值为 180.0 时,则会使过渡更改为从右到左。 默认值为 0.0.
此属性可用作数据绑定的源。修改此属性后,将调度 propertyChange 事件。
public function get angle():Number public function set angle(value:Number):void| LinearGradient | () | 构造函数 |
public function LinearGradient()构造函数。
| begin | () | 方法 |
public function begin(target:Graphics, rc:Rectangle):void开始填充。
参数
target:Graphics — 要填充的目标 Graphics 对象。 | |
rc:Rectangle —
定义 target 内填充大小的 Rectangle 对象。如果 Rectangle 的尺寸大于 target 的尺寸,则将剪裁填充。如果 Rectangle 的尺寸小于 target 的尺寸,则将扩展填充以填充整个 target。
|
| end | () | 方法 |