Corner Radius in Adobe Air
1 answer
You can do this by implementing a custom border:
package your.package
{
import flash.display.*;
import flash.geom.*;
import flash.utils.*;
import mx.skins.halo.HaloBorder;
import mx.utils.GraphicsUtil;
public class RoundedBorder extends HaloBorder
{
private var topCornerRadius:Number;
private var bottomCornerRadius:Number;
private var setup:Boolean;
/**
* Get the CSS style attributes from the element to which to apply this
* gradient.
*/
private function readElementCssStyles():void
{
topCornerRadius = getStyle("cornerRadius") as Number;
if (!topCornerRadius)
{
topCornerRadius = 0;
}
bottomCornerRadius = getStyle("bottomCornerRadius") as Number;
if (!bottomCornerRadius)
{
bottomCornerRadius = topCornerRadius;
}
}
/**
* Paint the gradient background.
*
* @param unscaledWidth
* @param unscaledHeight
*
*/
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var rectWidth:Number
= unscaledWidth - this.borderMetrics.left - this.borderMetrics.right;
var rectHeight:Number
= unscaledHeight - this.borderMetrics.top - this.borderMetrics.bottom;
readElementCssStyles();
var topRadius:Number = Math.max(topCornerRadius-2, 0);
var bottomRadius:Number = Math.max(bottomCornerRadius-2, 0);
GraphicsUtil.drawRoundRectComplex(this.graphics,
this.borderMetrics.left,
this.borderMetrics.top,
rectWidth,
rectHeight,
topRadius,
topRadius,
bottomRadius,
bottomRadius);
}
}
}
Then in your MXML application, you need to define a CSS class for your VBox like this:
<mx:Style>
.roundedBorder
{
border-style:solid;
border-thickness: 1;
border-skin: ClassReference("your.package.RoundedBorder");
corner-radius: 5;
}
</mx:Style>
I have ripped this code from a more complex class. I hope I haven't forgotten anything and that it will work as posted.
+1
source to share