3 Replies Latest reply on Jan 28, 2011 5:30 PM by peteandrus

    CheckBox in an itemRenderer not catching currentStateChanged?

    peteandrus Level 1

      i have an itemRenderer with a checkBox. it works great thanks in no small part to some of the people on this forum.

       

      However, more trouble has arisen! Here is the code:

       

      s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx"
                      autoDrawBackground="true" initialize="init()">
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
             
          </fx:Declarations>
          <fx:Script>
              <![CDATA[
                  import mx.binding.utils.BindingUtils;
                  import mx.events.StateChangeEvent;
                  [Bindable]
                  private var trueOrFalse:Boolean;
                  private function init():void
                  {
                     
                  }
                  private function changeFontColor():void
                  {
                     
                      if(check.selected){
                          check.setStyle("color","black");
                      }else{
                          check.setStyle("color","red");
                      }
                  }

       

                  protected function check_currentStateChangeHandler(event:StateChangeEvent):void
                  {
                      //do stuff
                  }

       

              ]]>
          </fx:Script>
         
         
          <s:CheckBox id="check" currentStateChange="check_currentStateChangeHandler(event)" selected="{data.selected}"   click="changeFontColor()" label="{data.label}">
             
          </s:CheckBox>
      </s:ItemRenderer>

       

       

      originally i just had the 'changeFontColor" method assigned to the 'click' event, but then i added a checkBox (outside the list where i use these itemRenderers) that, when checked, changes the selected value of each checkBox in the List to its value (basically, if it's checked, then all rendered checkBoxes in the List do the same.. .and vice versa).

       

      anyways, since the selected field in 'check' is bound to the dataProvider's 'selected' field, shouldn't the 'currentStateChanged' event fire whenever i change the value of 'data.selected'?

       

      i do this currently, but no currentStateChanged event fires. I want the color of these itemRenderers to change whenever i hit the checkBox outside the List as well as when i click on them.

       

      thanks!