1 Reply Latest reply on Apr 26, 2011 6:44 PM by finster26

    Changing color value <s:SolidColorStroke DataGridItemRenderer

    finster26

      I am unable to get the DataGridItemRenderer to pass a color value to "<s:SolidColor"  based on the function containing an if statement based on the value of data.Bld_Type. Code below.  I am vey new to Flex and not sure what the problme is. Any help would be appreciated.  I have tried passing a hex number and color name. Neither work. Thank you.

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        focusEnabled="true">
         
          <fx:Script>
              <![CDATA[
               import mx.events.FlexEvent;
             
              private var swatchCOL:uint;
             
              /** color function **/
              private function onLoad():void
              {
                  if(data.Bld_Type == "Office")
                      {
                      swatchCOL="ee7970";
                      //***<!--swatchCOL="red";-->
                     
                      }   
                  else if(data.Bld_Type == "Office/Warehouse")
                      {
                      swatchCOL="70b2ee";
                      //***<!--swatchCOL="blue";-->
                      }
              }  
              ]]>
          </fx:Script>

       

          <s:Group left="10" right="10" top="10" bottom="10">
              <s:Rect width="25" height="25">
                  <s:stroke>
                      <s:SolidColorStroke color="green" weight="2"/>                       
                  </s:stroke>
                  <s:fill>
                      <s:SolidColor color="swatchCOL"/>
                  </s:fill>
              </s:Rect>
          </s:Group>

       

      </s:MXDataGridItemRenderer>

        • 1. Re: Changing color value <s:SolidColorStroke DataGridItemRenderer
          finster26 Level 1

          Solution:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                    xmlns:s="library://ns.adobe.com/flex/spark"
                                    xmlns:mx="library://ns.adobe.com/flex/mx"
                                    focusEnabled="true">
             
              <fx:Script>
                  <![CDATA[
                      import mx.events.FlexEvent;
                     
                      [Bindable]
                      private var swatchCOL:uint;
                     
                      /** color function **/
                      override public function set data(value:Object):void {     
                          if(value != null)  {
                              super.data = value;
                              if(data.Bld_Type == "Office")
                              {
                                  swatchCOL=0xee7970;
                                 
                              }                
                              else if(data.Bld_Type == "Office/Warehouse")
                              {
                                  swatchCOL=0x70b2ee;
                                 
                              }
                              else
                              {   
                                  swatchCOL=0x003399;
                              }
                          }  
                          // Dispatch the dataChange event.
                          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));

           

                      }  
                  ]]>
              </fx:Script>

           

              <s:Group left="10" right="10" top="10" bottom="10">
                  <s:Rect id="rectFill" width="25" height="25" >
                      <s:stroke>
                          <s:SolidColorStroke color="black" weight="1"/>                       
                      </s:stroke>
                      <s:fill>
                          <s:SolidColor id="boxFill" color="{swatchCOL}"/>
                      </s:fill>
                  </s:Rect>
              </s:Group>
                 
          </s:MXDataGridItemRenderer>