1 Reply Latest reply on Dec 8, 2009 11:02 PM by Shongrunden

    getCurrentRendererState in ItemRenderers

    supdun421

         I tried overriding my getCurrentRendererState to updated my states. Unfortunately, my components do not updated after I switch my current state. Has anyone seen a problem similar to mine.

       

      <?xml version="1.0" encoding="utf-8"?>
      <!-- http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/ -->
      <s:ItemRenderer
                          xmlns:fx="http://ns.adobe.com/mxml/2009"
                          xmlns:s="library://ns.adobe.com/flex/spark"
                          focusEnabled="false">
           
           <s:states>
                <s:State name="normal" />
                <s:State name="hovered" />
                <s:State name="activate" />
                <s:State name="disabled" />
           </s:states>
           
           <fx:Script>
                <![CDATA[
                     import mx.events.FlexEvent;
                     
                     private var isActive:Boolean = false;
                     
                     override public function set label(value:String):void 
                     {
                          super.label = value;
                          labelElement.text = label; 
                     }
                     
                     override protected function commitProperties() : void
                     {
                          super.commitProperties();
                          addEventListener(MouseEvent.CLICK, onToggle, false, 0, true);
                     }
                     
                     private function onToggle(e:MouseEvent):void
                     {
                          isActive = !isActive;
                          this.currentState = getCurrentRendererState();
                     }
                     
                     override protected function getCurrentRendererState() : String
                     {
                          var skinState:String = super.getCurrentRendererState();
                          
                          if ( isActive ) 
                               skinState = "activate";
                          
                          return skinState;
                     }
                     
                     
                     
                ]]>
           </fx:Script>
           
           <s:Graphic id="background_rect" viewWidth.activate="300" >    
                <s:Rect id="rect1" width="100" height="20">
                     <s:fill>
                          <s:SolidColor id="sc1" color="0xFFFFCC" 
                                                        color.hovered="0xFFCCCC" 
                                                      color.activate="0x0000ff"
                                                      color.normal="0xCCCCCC"  />
                     </s:fill>
                </s:Rect>
           </s:Graphic>
           <s:Label id="labelElement"
                      color="0x000000"
                      color.normal="0x000000"
                      color.hovered="0xCCCCCC"
                      color.activate="0xffffff"
                      verticalCenter="0"
                      left="3" right="3"
                      top="6" bottom="4" />
      </s:ItemRenderer>