Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3255974
  • 博文数量: 530
  • 博客积分: 13360
  • 博客等级: 上将
  • 技术积分: 5473
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-13 13:32
文章分类

全部博文(530)

文章存档

2017年(1)

2015年(2)

2013年(24)

2012年(20)

2011年(97)

2010年(240)

2009年(117)

2008年(12)

2007年(8)

2006年(9)

分类: 系统运维

2011-10-22 17:32:00

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.源代码
  1. package mx.graphics
  2. {

  3. import flash.display.Graphics;
  4. import flash.events.EventDispatcher;
  5. import flash.geom.Point;
  6. import flash.geom.Rectangle;

  7. import mx.events.PropertyChangeEvent;

  8. [DefaultProperty("color")] //默认属性为color

  9. /**
  10.  *表示一个颜色及透明度
  11.  */
  12. public class SolidColor extends EventDispatcher implements IFill
  13. {
  14.     include "../core/Version.as";

  15.      /**
  16.      *构造函数 .
  17.       */
  18.     public function SolidColor(color:uint = 0x000000, alpha:Number = 1.0)
  19.      {
  20.         super();

  21.         this.color = color;
  22.         this.alpha = alpha;
  23.     }
  24.     
  25.     //属性alpha
  26.     private var _alpha:Number = 1.0;
  27.     
  28.     [Bindable("propertyChange")]
  29.     [Inspectable(category="General", minValue="0.0", maxValue="1.0")]
  30.     public function get alpha():Number
  31.     {
  32.         return _alpha;
  33.     }
  34.     
  35.     public function set alpha(value:Number):void
  36.     {
  37.         var oldValue:Number = _alpha;
  38.         if (value != oldValue)
  39.         {
  40.             _alpha = value;
  41.             dispatchFillChangedEvent("alpha", oldValue, value);
  42.         }
  43.     }
  44.     

  45.     // 属性 color
  46.     private var _color:uint = 0x000000;
  47.     
  48.     [Bindable("propertyChange")]
  49.     [Inspectable(category="General", format="Color")]
  50.     public function get color():uint
  51.     {
  52.         return _color;
  53.     }
  54.     
  55.     public function set color(value:uint):void
  56.     {
  57.         var oldValue:uint = _color;
  58.         if (value != oldValue)
  59.         {
  60.             _color = value;
  61.             dispatchFillChangedEvent("color", oldValue, value);
  62.         }
  63.     }
  64.     
  65.     // 方法
  66.     /**
  67.      * @接口mx.graphics.IFill定义的方法
  68.      */
  69.     public function begin(target:Graphics, targetBounds:Rectangle, targetOrigin:Point):void
  70.     {
  71.         target.beginFill(color, alpha);
  72.     }
  73.     
  74.     /**
  75.      * @接口mx.graphics.IFill定义的方法
  76.      */
  77.     public function end(target:Graphics):void
  78.     {
  79.         target.endFill();
  80.     }
  81.     
  82.     /**
  83.      * @private
  84.      */
  85.     private function dispatchFillChangedEvent(prop:String, oldValue:*, value:*):void
  86.     {
  87.         if (hasEventListener("propertyChange"))
  88.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, prop,
  89.              oldValue, value));
  90.     }
  91. }

  92. }

参考文献
1.SolidColor类参考.%28%29
2.代码参考.
阅读(4018) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~