1 Reply Latest reply on Mar 9, 2010 6:05 PM by David_F57

    Display not updating on currentState change...

    rcanulla Level 1

      Hi there,

       

      I've ran into this a few times now. I have a method in my custom component that changes the components currentState. In the response to an event, this method is called but doesn't update the display list... I've added trace statements and the method is being called, and the currentState is in fact changing, but nothing happens.

       

      That said, when I add a button inside my component that calls the same method, it works... Am I missing something?

       

      method inside custom component

                     public function editSearch():void {
                          this.currentState = 'preferences';
                          trace("change state");
                          trace(this.currentState);
                     }
      
        • 1. Re: Display not updating on currentState change...
          David_F57 Level 5

          Hi,

          Without the full code its difficult to see what the problem is,, it could be that you have default states in your component that override an external effort to change the state but once the component has 'focus' it functions correctly, if you are using skins this could also have an effect on the logic required to ensure that the state changes.

           

          This is the most simple example of controlling a state from the parent and works without issue. Also updating to the latest nightly build is always helpful just incase you have stumbled across an issue that may have already been resolved.

           

          ====== Application ======

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

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

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

             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

             xmlns:ns1="*">

          <fx:Script>

          <![CDATA[

          protected function button1_clickHandler(event:MouseEvent):void

          {

          pnl.toggleState();

          }

           

          ]]>

          </fx:Script>

          <ns1:myPanel x="333" y="329" id="pnl"/>

          <s:Button x="333" y="279" label="Button" click="button2_clickHandler(event)"/>

          </s:Application>

           

          ====== Component =========

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

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

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

          xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">

          <s:states>

          <s:State name="State1"/>

          <s:State name="other"/>

          </s:states>

          <fx:Script>

          <![CDATA[

           

          public function toggleState(): void

          {

          if (currentState == 'State1') currentState='other' else currentState='State1';

          }

           

          ]]>

          </fx:Script>

           

          <s:Button x="61" y="39" label="Button" includeIn="State1"/>

          <s:Button x="61" y="101" label="Button" includeIn="State1"/>

          <s:CheckBox x="61" y="159" label="CheckBox" includeIn="State1"/>

          <s:Button includeIn="other" x="28" y="45" label="Button"/>

          <s:Button includeIn="other" x="164" y="45" label="Button"/>

          <s:Button includeIn="other" x="289" y="45" label="Button"/>

          <s:CheckBox includeIn="other" x="164" y="165" label="CheckBox"/>

          </s:Panel>