5 Replies Latest reply on Nov 19, 2011 1:38 PM by kevinklin

    I only want state to change when set data is called in GridItemRenderer

    nikos101 Level 2

      I have a here  GridItemRenderer, however when the user mouse overs it the states reverts to critical, I only want state to change when set data is called

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"

                          xmlns:s="library://ns.adobe.com/flex/spark"

                          xmlns:mx="library://ns.adobe.com/flex/mx"

                          clipAndEnableScrolling="true" currentState="critical">

         

          <fx:Script>

              <![CDATA[

                  import utils.UsefulConstants;

                  override public function set data(value:Object):void

                  {

                      super.data = value;

                      //set the red text to show the old value

                      if(data){

                          if(!data.dateAcknowledged){

                              this.currentState = 'critical';

                          }

                          else if(data.dateReceived.time - data.dateReceived.time > UsefulConstants.oneDay){

                              this.currentState = 'warning';

                          }

                          else if(data.dateReceived.time - data.dateReceived.time < UsefulConstants.oneDay){

                              this.currentState = 'safe';

                          }

                          else if(data.status == 'CLOSED'){

                              this.currentState = 'safe';

                          }

                          else{

                              throw new Error('Unforseen condtions for data.dateReceived.time - data.dateReceived.time');

                          }

                      }

                  }

              ]]>

          </fx:Script>

          <s:states>

              <s:State name="critical"/>

              <s:State name="warning"/>

              <s:State name="safe"/>

          </s:states>

          <s:HGroup x="-1" y="-1" width="100%" horizontalAlign="center" verticalAlign="middle" height="100%" >

             

              <s:Graphic id="icon" includeIn="critical,warning" x="-1" y="5" width="16" height="20"

                         version="2.0" viewHeight="600" viewWidth="200">

                  <s:Ellipse width="88" height="401" x="58" y="37">

                      <s:fill>

                          <s:SolidColor alpha="1" color="#FE4744"

                                        color.warning="#Ff7f45"/>

                      </s:fill>

                      <s:stroke>

                          <s:SolidColorStroke color="#FE3D44" alpha="1" weight="1"/>

                      </s:stroke>

                  </s:Ellipse>

                  <s:Ellipse width="51" height="97" x="79" y="478">

                      <s:fill>

                          <s:SolidColor alpha="1" color="#FD8E9E"

                                        color.warning="#f69240"/>

                      </s:fill>

                      <s:stroke>

                          <s:SolidColorStroke color="#942EC8" alpha="0.62"/>

                      </s:stroke>

                     

                  </s:Ellipse>

                  <s:Ellipse width="31" height="147" x="72" y="122">

                      <s:fill>

                          <s:SolidColor alpha="1" color="#FD8E9E"

                                        color.warning="#f69240"/>

                      </s:fill>

                      <s:stroke>

                          <s:SolidColorStroke color="#942EC8" alpha="0.62"/>

                      </s:stroke>

                  </s:Ellipse>

             

              </s:Graphic>

              <s:Graphic

                         includeIn="safe" width="20" height="20" version="2.0"

                         viewHeight="600" viewWidth="600">

                  <s:Path data="M49,294 L245,410L551,116C551,116 259,519 257,516L49,294Z " winding="nonZero" x="-13.5" y="-57.3" scaleX="1.051689863204956" scaleY="1.122194528579712">

                      <s:fill>

                          <s:LinearGradient x="49" y="115.95" scaleX="402.4029386075604" rotation="18.660078428615776">

                              <s:GradientEntry color="#359F66" ratio="0.006535947712418301"/>

                              <s:GradientEntry color="#7EFA4A" ratio="0.9803921568627451"/>

                          </s:LinearGradient>

                      </s:fill>

                      <s:stroke>

                          <s:SolidColorStroke color="#C6A470" alpha="1" weight="1"/>

                      </s:stroke>

                  </s:Path>

              </s:Graphic>

       

             

          </s:HGroup>

      </s:GridItemRenderer>

        • 1. Re: I only want state to change when set data is called in GridItemRenderer
          kevinklin Adobe Employee

          Override getCurrentRendererState() to return the correct state depending on the data.

          • 2. Re: I only want state to change when set data is called in GridItemRenderer
            nikos101 Level 2

            cheers mate, its sometime hard keeping upto date with how things changed in spark

            • 3. Re: I only want state to change when set data is called in GridItemRenderer
              nikos101 Level 2

              I have only 2 items in my dp, however this only gets called once when the db is assigned:

               

              override protected function getCurrentRendererState():String
              {
              super.getCurrentRendererState();
              if(data){
              if(!data.dateAcknowledged){
              return 'critical';
              }
              else if(data.dateAcknowledged.time - data.dateReceived.time >= UsefulConstants.oneDay){
              return 'warning';
              }
              else if(data.dateAcknowledged.time - data.dateReceived.time < UsefulConstants.oneDay){
              return 'safe';
              }
              else if(data.status == 'CLOSED'){
              return 'safe';
              }
              else{
              throw new Error('Unforseen condtions for data.dateReceived.time - data.dateReceived.time');
              }
              trace(data.dateAcknowledged.time + ' ' + data.dateReceived.time + ' ' + UsefulConstants.oneDay);
              trace(data.dateAcknowledged.time - data.dateReceived.time + ' ' + UsefulConstants.oneDay);
              }
              return null;
              }
              • 4. Re: I only want state to change when set data is called in GridItemRenderer
                nikos101 Level 2

                if found just that just using getCurrentRendererState gave unreliable results so also using set data did what I wanted. ps how do you wrap your code in code?

                 

                 

                override protected function getCurrentRendererState():String
                {
                super.getCurrentRendererState();
                if(data){
                if(!data.dateAcknowledged){
                return 'critical';
                }
                else if(data.dateAcknowledged.time - data.dateReceived.time >= UsefulConstants.oneDay){
                return 'warning';
                }
                else if(data.dateAcknowledged.time - data.dateReceived.time < UsefulConstants.oneDay){
                return 'safe';
                }
                else if(data.status == 'CLOSED'){
                return 'safe';
                }
                else{
                throw new Error('Unforseen condtions for data.dateReceived.time - data.dateReceived.time');
                }
                trace(data.dateAcknowledged.time + ' ' + data.dateReceived.time + ' ' + UsefulConstants.oneDay);
                trace(data.dateAcknowledged.time - data.dateReceived.time + ' ' + UsefulConstants.oneDay);
                }
                return null;
                }
                override public function set data(value:Object):void
                {
                // TODO Auto Generated method stub
                super.data = value;
                if(data){
                if(!data.dateAcknowledged){
                this.currentState = 'critical';
                }
                else if(data.dateAcknowledged.time - data.dateReceived.time >= UsefulConstants.oneDay){
                this.currentState =  'warning';
                }
                else if(data.dateAcknowledged.time - data.dateReceived.time < UsefulConstants.oneDay){
                this.currentState =  'safe';
                }
                else if(data.status == 'CLOSED'){
                this.currentState =  'safe';
                }
                else{
                throw new Error('Unforseen condtions for data.dateReceived.time - data.dateReceived.time');
                }
                trace(data.dateAcknowledged.time + ' ' + data.dateReceived.time + ' ' + UsefulConstants.oneDay);
                trace(data.dateAcknowledged.time - data.dateReceived.time + ' ' + UsefulConstants.oneDay);
                }
                }
                • 5. Re: I only want state to change when set data is called in GridItemRenderer
                  kevinklin Adobe Employee

                  Yes, you need to put something like this in both set data and getCurrentRendererState().

                   

                  I'm not sure...seems to be a problem on the forums recently with copy/paste.

                  1 person found this helpful