免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2341 | 回复: 0

mx.graphics.SolidColor源代码解析 [复制链接]

论坛徽章:
0
发表于 2011-12-23 02:44 |显示全部楼层
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类参考.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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP