我正在开发一个Flex mobil
电子应用程序,并一直在优化其在移动设备上的性能。我已经读过皮肤必须被写入ActionScript
所以我试图创建我的 AS ButtonSkin
。
public class mButtonSkin extends ButtonSkin
{
private static var colorMatrix:Matrix = new Matrix();
protected var radiusX:Number = 12;
protected var mAngle:Number = 30;
protected var labelWidth:Number;
protected var labelHeight:Number;
protected var paddingLeft:Number = 12;
protected var paddingRight:Number = 12;
protected var paddingTop:Number = 2;
protected var paddingBottom:Number = 2;
public function mButtonSkin() {
super();
}
override protected function drawBackground(unscaledWidth:Number,unscaledHeight:Number) : void {
colorMatrix.createGradientBox(width,height,mAngle);
if (currentState == "up") {
graphics.beginGradientFill(GradientType.LINEAR,
[hostComponent.getStyle("fill3"),hostComponent.getStyle("fill1")], [1,1], [0,255], colorMatrix);
} else {
graphics.beginFill(hostComponent.getStyle("fill4"));
}
graphics.lineStyle(0.5,hostComponent.getStyle("borderColor"),0.5);
graphics.drawRoundRect(0,0,hostComponent.width,hostComponent.height,12);
graphics.endFill();
}
override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number) : void {
labelDisplay.wordWrap = true;
labelDisplay.multiline = true;
labelDisplay.commitStyles();
labelWidth = width - paddingLeft - paddingRight;
labelHeight = height - paddingTop - paddingBottom;
var x:Number = width / 2 - labelWidth / 2;
var y:Number = height / 2 - getElementPreferredHeight(labelDisplay) / 2;
setElementSize(labelDisplay,labelWidth,labelHeight);
setElementPosition(labelDisplay,x,y);
}
override protected function labelDisplay_valueCommitHandler(event:FlexEvent) : void {
labelDisplayShadow.text = "";
}
}
在我的按钮中应用这个皮肤:
按钮 labelDisplay 对齐错误(verticalAlignment 必须居中)。
点击按钮后:
我的按钮labelDisplay
现在垂直对齐到中间。
我错过了什么?我做错了什么?