mx:button fillColors不工作

时间:2012-04-17 16:28:38

标签: actionscript-3 flex flash-builder

我使用FB4.6并尝试在我的按钮上应用fillColor。

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;
        }



    }
}

但这对我的按钮没有影响。

你能帮助我吗?

由于

2 个答案:

答案 0 :(得分:2)

你传入一个字符串'[0x86C543,0xE6E6E6]',你需要一个数组。 []括号表示一个数组,但通过将其放在引号中,它将作为字符串读入。

将此更改为

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

答案 1 :(得分:0)

fillColors上的

mx: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并不重要,因为您需要使用光环主题事项。因此,如果您想要更改mx:Button的fillColors,您有两个我之前发布的选择