1.創建一個VButton的自定義類,繼承與button,重寫initialize()方法,爲labelDisplay的text屬性顯示的文本添加回車,貼出代碼如下:
package components{
import spark.components.Button;
/**
* flex4中豎向按鈕
* @author
* @version 1.0.0
* 創建時間:Nov 11, 2013 11:07:04 AM
*/
public class VButton extends Button{
public function VButton(){
}
override public function initialize():void{
super.initialize();
var length:int = this.label.length;
var newText:String = "";
for(var i:int = 0; i < length; i++){
newText+=this.label.charAt(i)+"\n";
}
this.labelDisplay.text = newText;
trace(newText);
}
}
}
2.需要自定義buttonskin,將id爲labelDisplay的label組件的maxDisplayedLines屬性更改爲-1 即可。
<s:Label id="labelDisplay"
textAlign="center"
maxDisplayedLines="-1"
horizontalCenter="0" verticalCenter="1" verticalAlign="middle"
left="2" right="2" top="2" bottom="2" >
</s:Label>