4 Replies Latest reply on Oct 25, 2010 5:33 AM by BhaskerChari

    enterState Event

    daslicht Level 2

      Why is this not working ?

       

       

       

      <?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"
                        enterState="application1_enterStateHandler(event)"
                        >
           <fx:Script>
                <![CDATA[
                     import mx.events.FlexEvent;

                     protected function application1_enterStateHandler(event:FlexEvent):void
                     {
                          trace('state changed'+ this.currentState);
                     }

                ]]>
           </fx:Script>
           <s:states>
                
                <s:State name="one"/>
                <s:State name="two"/>
           </s:states>
           
           <s:Label text.one="one" text.two="two"  x='3' y='3'/>
           <s:Button label='2'  click="{currentState='two'}" x="48" y="66"/>
           <s:Button label ='1' click="{currentState='one'}" x="126" y="66"/>
           
           
      </s:Application>

        • 1. Re: enterState Event
          allen.brown Level 1

          In what way is it not working?

           

          I just cut and paste the whole thing into Flex Builder 4, ran it and it behaved fine.

          • 2. Re: enterState Event
            daslicht Level 2

            it is not tracing anything here ?!

            • 3. Re: enterState Event
              daslicht Level 2

              Here try this:

              http://wensauer.info/flex/flex_state_change_events/

               

              It should show a Alert on enter and exit viewState.

               

              I tried adding the event Listener in two different ways, both do not work !

               

              What am I missing ?

              • 4. Re: enterState Event
                BhaskerChari Level 4

                Hi daslicht,

                 

                Try currentStateChange  event instead of enterState event.

                 

                currentStateChange is Dispatched after the view state has completed changing. It is dispatched by a component after its currentState property changes.

                 

                <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"
                                  currentStateChange ="application1_enterStateHandler(event)"
                                  >

                 

                and your function should look like  as below. Notice that the event type is changed here from FlexEvent to StateChangeEvent.

                 

                protected function application1_enterStateHandler(event:StateChangeEvent):void              
                  {                   
                   Alert.show('state changed'+ this.currentState);              
                  } 

                 

                Thanks,

                Bhasker