看多了很多关于设置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>