1
我正在致力於Flex mobil
e應用程序,並且一直在優化其在移動設備上的性能。我已閱讀皮膚必須寫在ActionScript
,所以我試圖創建我的AS ButtonSkin
。Flex移動按鈕在ActionScript中的皮膚 - 多行標籤Display
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
現在是垂直對齊到中間。
我錯過了什麼嗎?我做錯了什麼?
請注意,我已將/ 2更改爲* .5。這是因爲我讀過一些博客,其中的乘法運算速度比分區快。 :)無論如何,只是想分享這一點。 – wens 2013-04-17 10:34:19