Not yet rated
Tags:



Problem

I have a list control with ItemRenderer containing a Button. I need to change Button color for each instance within my ArrayCollection. How can I use the skin class to apply different colors for each button?

Solution

There are two solutions and I have provided the details below.

Detailed explanation

#1

In your ItemRenderer override the set data property and dynamically set the chromeColor based on the data, this also still gives you nice gradient normal, hover and click colors and effects.

        override public function set data(value:Object):void
{
  super.data = value;
  btn.setStyle("chromeColor", data.color);

}
 
 
  

#2

SubClass Button and implement a backgroundColor style property create a new skin for you custom button based on the ButtonSkin and then draw the set backgroundColor from the hostComponent in the skin.

I just found an article from James Ward, so I will let credit for this part of the answer go to him :)
http://www.jamesward.com/2010/07/30/how-to-define-styles-on-skins-in-flex-4/


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes