2009-10-31 60 views
6

標準的Flex按鈕不允許標籤文本換行。我在互聯網上讀到,有一些無證的方式來處理這個問題,但我沒有讓他們工作。如果有人能張貼我一個小例子會很棒!Adob​​e Flex:按鈕標籤中的Word換行

+0

你應該繼續並接受基督教的Nunciato的答案。 – Panzercrisis 2012-07-26 14:51:42

回答

15

基本上你需要設置按鈕的文本字段控制(多和將wordWrap),你不能沒有擴展Button類做一些保護特性。所以,如果你創建擴展按鈕,並設置其屬性和它一點點工作,使新一類的東西量出正確:

package 
{ 
    import flash.text.TextFieldAutoSize; 
    import mx.controls.Button; 

    public class WrappingButton extends Button 
    { 


     public function WrappingButton() 
     { 
      super(); 
     } 

     override protected function createChildren():void 
     { 
      super.createChildren(); 

      textField.multiline = true; 
      textField.wordWrap = true; 
      textField.autoSize = TextFieldAutoSize.CENTER; 
     } 

     override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void 
     { 
      super.updateDisplayList(unscaledWidth, unscaledHeight); 
      textField.y = (this.height - textField.height) >> 1; 

      height = textField.height + getStyle("paddingTop") + getStyle("paddingBottom"); 
     } 
    } 
} 

...你可以丟棄控制到MXML像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*"> 

    <local:WrappingButton label="The quick brown fox jumped over the lazy dog." width="100" paddingTop="10" paddingBottom="10" /> 

</mx:Application> 

希望它有幫助!如果你有他們的問題,請回復問題。

+1

大組成部分,但我試圖使用它作爲一個自定義項目渲染和updateDisplayList()被調用無限循環。 – Laramie 2010-10-22 21:04:28

+0

如何在Flash Builder 4.6中使用相同的組件?當我在'textField'上出現錯誤'「訪問未定義的屬性」 – abi1964 2013-05-08 13:46:41

4

使用&#13;

嘗試我使用

<s:Button label="Top two&#13;states result" height="100%" width="100%" icon="@Embed(source='assets/bar.png')" chromeColor="#A3F4FD"/> 

和它多行標籤。

+0

太棒了,就像一個魅力! – Ska 2012-02-11 04:27:37