- 論壇徽章:
- 0
|
1.概述 定義顏色的表示形式,包括顏色值和 alpha 值。
2.常見屬性和方法 2.1 屬性alpha
Number 類型,默認(rèn)值為 1.0. 顏色的透明度?赡艿闹禐 0.0(不可見)到 1.0(不透明)。 可用作數(shù)據(jù)綁定的源。修改此屬性后,將調(diào)度 propertyChange 事件。 實(shí)現(xiàn) public function get alpha():Number public function set alpha(value:Number):void
2.2 屬性color
uint類型 表示顏色值。可用作數(shù)據(jù)綁定的源。修改此屬性后,將調(diào)度 propertyChange 事件。 實(shí)現(xiàn) public function get color():uint public function set color(value:uint):void
2.3 方法begin()
public function begin(target:Graphics, rc:Rectangle):void 開始填充。 參數(shù) target:Graphics — 要填充的目標(biāo) Graphics 對(duì)象。 rc:Rectangle — 定義 target 內(nèi)填充大小的 Rectangle 對(duì)象。如果 Rectangle 的尺寸大于 target 的尺寸,則將剪裁填充。如果 Rectangle 的尺寸小于 target 的尺寸,則將擴(kuò)展填充以填充整個(gè) target。
2.4 方法end() public function end(target:Graphics):void 結(jié)束填充。 參數(shù) target:Graphics — 要填充的 Graphics 對(duì)象。
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")] //默認(rèn)屬性為color
-
-
/**
-
*表示一個(gè)顏色及透明度
-
*/
-
public class SolidColor extends EventDispatcher implements IFill
-
{
-
include "../core/Version.as";
-
-
/**
-
*構(gòu)造函數(shù) .
-
*/
-
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));
-
}
-
}
-
-
}
參考文獻(xiàn) 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
|
|