- 论坛徽章:
- 0
|
1.概述 定义颜色的表示形式,包括颜色值和 alpha 值。
2.常见属性和方法 2.1 属性alpha
Number 类型,默认值为 1.0. 颜色的透明度。可能的值为 0.0(不可见)到 1.0(不透明)。 可用作数据绑定的源。修改此属性后,将调度 propertyChange 事件。 实现 public function get alpha():Number public function set alpha(value:Number):void
2.2 属性color
uint类型 表示颜色值。可用作数据绑定的源。修改此属性后,将调度 propertyChange 事件。 实现 public function get color():uint public function set color(value:uint):void
2.3 方法begin()
public function begin(target:Graphics, rc:Rectangle):void 开始填充。 参数 target:Graphics — 要填充的目标 Graphics 对象。 rc:Rectangle — 定义 target 内填充大小的 Rectangle 对象。如果 Rectangle 的尺寸大于 target 的尺寸,则将剪裁填充。如果 Rectangle 的尺寸小于 target 的尺寸,则将扩展填充以填充整个 target。
2.4 方法end() public function end(target:Graphics):void 结束填充。 参数 target:Graphics — 要填充的 Graphics 对象。
3.源代码
- package mx.graphics
-
{
-
-
import flash.display.Graphics;
-
import flash.events.EventDispatcher;
-
import flash.geom.Point;
-
import flash.geom.Rectangle;
-
-
import mx.events.PropertyChangeEvent;
-
-
[DefaultProperty("color")] //默认属性为color
-
-
/**
-
*表示一个颜色及透明度
-
*/
-
public class SolidColor extends EventDispatcher implements IFill
-
{
-
include "../core/Version.as";
-
-
/**
-
*构造函数 .
-
*/
-
public function SolidColor(color:uint = 0x000000, alpha:Number = 1.0)
-
{
-
super();
-
-
this.color = color;
-
this.alpha = alpha;
-
}
-
-
//属性alpha
-
private var _alpha:Number = 1.0;
-
-
[Bindable("propertyChange")]
-
[Inspectable(category="General", minValue="0.0", maxValue="1.0")]
-
public function get alpha():Number
-
{
-
return _alpha;
-
}
-
-
public function set alpha(value:Number):void
-
{
-
var oldValue:Number = _alpha;
-
if (value != oldValue)
-
{
-
_alpha = value;
-
dispatchFillChangedEvent("alpha", oldValue, value);
-
}
-
}
-
-
-
// 属性 color
-
private var _color:uint = 0x000000;
-
-
[Bindable("propertyChange")]
-
[Inspectable(category="General", format="Color")]
-
public function get color():uint
-
{
-
return _color;
-
}
-
-
public function set color(value:uint):void
-
{
-
var oldValue:uint = _color;
-
if (value != oldValue)
-
{
-
_color = value;
-
dispatchFillChangedEvent("color", oldValue, value);
-
}
-
}
-
-
// 方法
-
/**
-
* @接口mx.graphics.IFill定义的方法
-
*/
-
public function begin(target:Graphics, targetBounds:Rectangle, targetOrigin:Point):void
-
{
-
target.beginFill(color, alpha);
-
}
-
-
/**
-
* @接口mx.graphics.IFill定义的方法
-
*/
-
public function end(target:Graphics):void
-
{
-
target.endFill();
-
}
-
-
/**
-
* @private
-
*/
-
private function dispatchFillChangedEvent(prop:String, oldValue:*, value:*):void
-
{
-
if (hasEventListener("propertyChange"))
-
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, prop,
-
oldValue, value));
-
}
-
}
-
-
}
参考文献 1.SolidColor类参考.http://livedocs.adobe.com/flex/3_cn/langref/mx/graphics/SolidColor.html#begin%28%29 2.代码参考.http://opensource.adobe.com/svn/opensource/flex/sdk/trunk/frameworks/projects/framework/src/mx/graphics/SolidColor.as
|
|