AS3:Graphics.lineStyle() - 仅更改ALPHA?

时间:2010-01-19 17:16:40

标签: flex flash actionscript-3

在方法Graphics.lineStyle()中,您将alpha作为第三个参数传递。我不想改变前两个参数的厚度或颜色,所以我有没有办法改变alpha?或至少“获得”厚度和颜色,以便我可以重新通过它们,以便它们不会改变?

谢谢!

1 个答案:

答案 0 :(得分:2)

一个选项是包装您传递的图形对象,并为单个属性添加getter和setter,否则这些属性仅作为参数提供。

的伪代码:

public class CustomGraphics 
{
    // -- here is the wrapped graphics object
    protected var _graphics:Graphics;

    // -- unique properties for line style
    protected var _lineColor:uint;
    protected var _lineThickness:int;
    protected var _lineAlpha:Number;

    public function CustomGraphics( gfx:Graphics )
    {
          _graphics = gfx;
          _lineColor = 0;
          _lineThickness = 1;
          _lineAlpha = 1;

          draw();
    }

    public function set lineAlpha( value:Number ):void
    {
        if( _lineAlpha != value ) {
             _lineAlpha = value;
             // -- insert code to redraw or invalidate here
             draw();
        }
    }

    public function draw():void {
        _graphics.setLineStyle( _lineThickness, _lineColor, _lineAlpha );
    }
}