Flex RoundCorner

看多了很多关于设置VBox圆角的资料,研究了一天 ,终有所获,先发上来和大家分享一下.

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.utils.GraphicsUtil;
import flash.display.Graphics;

[Bindable]
public var gradientColors:Array;
[Bindable]
public var gradientAlphas:Array;
[Bindable]
public var gradientRatios:Array;
[Bindable]
public var gradientAngle:int;
[Bindable]
public var innerRadius:Number;
[Bindable]
public var roundCornerFlag : Boolean = true;
[Bindable]
public var topLeftRadius : Number = 0;
[Bindable]
public var topRightRadius : Number = 0;
[Bindable]
public var bottomLeftRadius : Number = 0;
[Bindable]
public var bottomRightRadius : Number = 0;

override protected function updateDisplayList(unscaledWidth : Number, unscaledHeight : Number) : void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var fillType:String = GradientType.LINEAR;
var colors:Array = gradientColors;
var alphas:Array = gradientAlphas;
var ratios:Array = gradientRatios;
var matrix:Matrix = new Matrix();
matrix.createGradientBox(unscaledWidth, unscaledHeight, (gradientAngle * Math.PI/180));

var spreadMethod:String = SpreadMethod.PAD;

graphics.clear();
graphics.beginGradientFill(fillType, colors, alphas, ratios, matrix, spreadMethod);
if(roundCornerFlag)
{
drawAllRoundCorner(graphics, unscaledWidth, unscaledHeight);
}
else
{
customizeRoundCorner(graphics, unscaledWidth, unscaledHeight);
}
graphics.endFill();
}

public function drawAllRoundCorner(graphics : Graphics, unscaledWidth : Number, unscaledHeight : Number) : void
{
if(isNaN(innerRadius))
{
graphics.drawRect(1, 1, unscaledWidth - 1, unscaledHeight - 1);
}
else
{
graphics.drawRoundRect(1, 1, unscaledWidth - 2, unscaledHeight - 2, innerRadius);
}

}

public function customizeRoundCorner(graphics : Graphics, unscaledWidth : Number, unscaledHeight : Number) : void
{
GraphicsUtil.drawRoundRectComplex(graphics, 1, 1, unscaledWidth - 2, unscaledHeight - 2,
topLeftRadius,topRightRadius, bottomLeftRadius, bottomRightRadius);
}


]]>
</mx:Script>
</mx:VBox>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值