buttonmobileviewcolorsflex-spark

FlashBuilder/Spark :: Mobile Project :: Change color of button in view actionbar


FlashBuilder/Spark mobile project view action bar.

Currently if you set the chromeColor of a button in the actionbar it only shows up when on the press state of the button. It does not change the color of the button default state. I could not find any way to style it.


Solution

  • After some digging I found that TransparentActionButtonSkin.as was overriding the drawBrackground function and specifically removing chromeColor and only allowing it to show on a the button down state.

    I overrode that "little gem" with my own class.

    package view_components
    {
        import mx.core.mx_internal; 
        import spark.skins.mobile.TransparentActionButtonSkin;
    
        use namespace mx_internal;
    
        public class ActionbarColoredButton extends TransparentActionButtonSkin
        {
            public function ActionbarColoredButton()
            {
                super();
            }
    
            override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
            {
                // omit super.drawBackground() to drawRect instead
                // only draw chromeColor in down state (transparent hit zone otherwise)
    
                //NO, I want colored action buttons
                var chromeColor:uint = getStyle(fillColorStyleName);
                var chromeAlpha:Number = 1;
    
                graphics.beginFill(chromeColor, chromeAlpha);
                graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
                graphics.endFill();
            }
        }
    }