2012-04-17 40 views
0

我使用FB4.6,我嘗試在我的按鈕上應用fillColor。mx:按鈕fillColors不起作用

package fr.int.component.customNavTab 
{ 
    import mx.controls.Button; 
    import mx.controls.ToggleButtonBar; 
    import mx.core.IFlexDisplayObject; 
    import mx.states.OverrideBase; 

    public class IconToggleButtonBar extends ToggleButtonBar 

    { 

     public function IconToggleButtonBar() 
     { 
      super(); 

     } 

     [Inspectable (enumeration='left,right,top,bottom', defaultValue='left')]   
     public var labelPlacement:String = 'left';   
     public var color:uint; 


     override protected function createNavItem(label:String, icon:Class=null):IFlexDisplayObject 
     { 
      var b:Button = Button (super.createNavItem(label,icon)); 
      b.labelPlacement = labelPlacement; 

      b.setStyle('fillColors', [0x86C543, 0xE6E6E6]); 
      return b; 
     } 



    } 
} 

但是這對我的按鈕沒有影響。

你能幫我嗎?

感謝

+1

嘗試刪除setStyle的第二個參數周圍的引號。 – Kodiak 2012-04-17 16:30:43

+0

應該工作...如何將fillAlphas設置爲[1,1]呢? – 2012-04-18 15:06:35

回答

2

你正在傳遞一個字符串'[0x86C543,0xE6E6E6]',你需要一個數組。 []括號表示一個數組,但通過將它放在引號中,它以字符串形式讀入。

更改爲

b.setStyle('fillColors', [0x86C543, 0xE6E6E6]); 
+0

我刪除了引用,但沒有效果。 – Flex60460 2012-04-17 19:09:24

+0

你使用的是MX還是火花按鈕? – francis 2012-04-17 19:14:08

+0

我使用mx按鈕謝謝 – Flex60460 2012-04-17 21:25:24

0

fillColorsmx:Button只能在Halo主題。所以你需要使用Flex 3 SDK或嘗試在Flex 4中http://blog.flexexamples.com/2009/07/14/using-the-halo-theme-in-flex-4/

編輯是這樣的: 下面是一個例子。嘗試使用Flex創建項目4 SDK,並把這個代碼的應用程序:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <fx:Style> 
     @namespace s "library://ns.adobe.com/flex/spark"; 
     @namespace mx "library://ns.adobe.com/flex/mx"; 
     mx|Button{ 
      fillColors: #FF0000, #00FF00 
     } 
    </fx:Style> 
    <mx:Button /> 
</s:Application> 

將會有一個警告The style 'fillColors' is only supported by type 'mx.controls.Button' with the theme(s) 'halo'.而且這不要緊,你正在使用mx:Button,事實上,你需要使用Halo主題事項。所以,如果你想要更改fillColors的mx:Button你有2個選擇,我已經發布

+0

正如你所看到的,他已經使用mx:Button來聲明import mx.controls.Button; – 2012-04-18 15:04:38

+0

我編輯了我的答案 – Art 2012-04-19 05:16:50