0 Replies Latest reply on Apr 23, 2010 10:09 PM by -skitch-

    Checkbox item renderer populated with data from 2 sources

    -skitch- Level 1

      I have a list object that has a check box and a label (using an inline item renderer).  The list itself is populated with an array of objects and whether the checkbox is selected takes those objects and adds them to another list (for outbound purposes).  Since the selected list can change elsewhere in my app how do I keep the binding of selections consistent?  The dataprovider for my checkbox list is the first array of objects and is binded, but the second one (selected array) is not.  What would be the best way to provide that binding to make sure the selected is consistent when the second array changes.  Some of the code is below to better show...

       

      <cms:HilightList

           id = "distributorList"

           width = "100%"

           height = "100%"

           drawHighlight="{ViewUtils.drawHighlightIndicator}"

           drawSelection="{ViewUtils.drawHighlightIndicator}"

           dataProvider="{pmDistributors.distributors}">

           <mx:itemRenderer>

                <mx:Component>

                     <mx:HBox>

                          <mx:CheckBox

                                             selected = "{outerDocument.isSelected(data)}"

                                 change = "{outerDocument.handleSelectedChange(event)}"/>

                          <mx:Label text="{data.name}"/>

                     </mx:HBox>

                </mx:Component>

           </mx:itemRenderer>

      </cms:HilightList>

       

       

      public function isSelected(item:Object):Boolean

      {

           var partner:Partner = item as Partner;

           var selected:Boolean = false;

           for each(var schedPartner:Partner in scheduleAssets.partners)

           {

                if(schedPartner.id == partner.id)

                {

                     selected = true;

                }

           }

           return selected;

      }

      public function handleSelectedChange(event:Event):void

      {

           var partner:Partner = event.currentTarget.parent.data as Partner;

                if(event.currentTarget.selected)

                {

                     addPartnerEvent(partner);

                } else {

                     removePartnerEvent(partner);

                }

           }

      }