0

I have about 8 checkboxes that are created dynamically using a for loop. Each checkbox has a different color. Basically i want to change the fillColor of every checkbox (label not included) using 8 predefined colors. Here's my code.

for (var i:int=0; i <= annotatorNames.length; i++)
{
    var checkbox:CheckBox = new CheckBox();
    var colorIndex:int = parseInt(annotatorColours[i]) - 1;
    var checkboxColor:String = UiConstants.ANNOTATOR_COLORS[colorIndex];

    checkbox.label=annotatorNames[i];
    checkbox.selected=true;
    checkbox.setStyle("fillColors", [checkboxColor, checkboxColor, checkboxColor, checkboxColor]);
    annotatorCheckboxes[i] = checkbox;
    this.addChild(checkbox);
}

For some reason fillCollors does not apply and the checkbox is not styled. If i style the label it works...also pretty much any other style applies..but not fillColors. What am I doing wrong here?

The code does not have errors and colors are in the form of "0XA52A2A".

user253530
  • 2,583
  • 13
  • 44
  • 61

2 Answers2

0

Try using a stylesheet, including something like:

CheckBox {
   fillColors: #yourColor, #yourColor, #yourColor, #yourColor;
}

import it by the following statement:

<mx:Style source="yourstylesheet.css"/>
Fseee
  • 2,476
  • 9
  • 40
  • 63
0

You have an issue with pieces of code that aren't in the example, i.e. the constants UiConstants.ANNOTATOR_COLORS[colorIndex]; etc

I trimmed your code to just the bare minimum to research your defect and the setting of the styles works without issue.

The following code works perfectly fine, run this and check it out:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
    <![CDATA[
        import mx.controls.CheckBox;
        private function init() : void {
            for (var i:int=0; i <= 8; i++)
            {
                var checkbox:CheckBox = new CheckBox();
                var checkboxColor:String = 'red';

                checkbox.label=i.toString();
                checkbox.selected=true;
                checkbox.setStyle("fillColors", [checkboxColor, checkboxColor, checkboxColor, checkboxColor]);
                holder.addChild(checkbox);
            }
        }
    ]]>
</mx:Script>
<mx:HBox id="holder"/>
</mx:Application>

That should point you in the right direction...

Nate
  • 2,881
  • 1
  • 14
  • 14
  • thank you but that does not work in my case, i have tried hardcoded "red" values and did not work. – user253530 Jul 12 '12 at 18:51
  • What I'm telling you is that the problem you are having, is not in the code you provided. If you run the sample code I posted, it works just fine. Your issue isn't in the code you provided. Can you create a small self-contained runable version of the issue? – Nate Jul 12 '12 at 19:02