3 Replies Latest reply on Oct 17, 2009 4:30 PM by bnther

    Navigate between states

    bnther

      Flex nubie here.

       

      I'm trying to wrap my head around 'states' as opposed to pages and I can't seem to figure out how go between states.  For the sake of learning, I started a new project with a base state and a second state, each with their own button.  I want to be able to click one and have that button send me to the opposing state.  In AS3 I'd do the MouseEvent.CLICK but I'm not sure that'll fly with Flex.

      Can someone give me a hint.

       

      Here's the code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Script>
              <![CDATA[
                  import mx.controls.*; // not really sure if these are the right controls
                  import mx.states.*; // ditto
                  private function basePage():void{
                    what goes here ?
                  }
                 
                  private function secondPage():void{
                    what goes here ?
                  }
              ]]>
          </mx:Script>

       

          <mx:states>
              <mx:State name="2nd state">
                  <mx:RemoveChild target="{button1}"/>
                  <mx:AddChild position="lastChild">
                      <mx:Button x="548" y="274" label="2nd state"  id="button2" click="basePage" />
                  </mx:AddChild>
              </mx:State>
          </mx:states>
          <mx:Button x="461" y="273" label="base state" id="button1" click="secondPage"/>
         
      </mx:Application>

        • 1. Re: Navigate between states
          salem_b_a Level 2

          Starting from the bottom,

          <mx:Button x="461" y="273" label="base state" id="button1" click="secondPage"/>

          should rather be <mx:Button x="461" y="273" label="base state" id="button1" click="secondPage(event)"/>

           

          then

          private function basePage():void{
                        //what goes here ?
                      }
                     
                      private function secondPage():void{
                        /:what goes here ?
                      }

          would be

          private function basePage(event:Event):void{
                        currentState='';
                      }
                     
                      private function secondPage(event:):void{Event
                        currentState='2nd state'
                      }

           

          and it is as simple as that;

           

           

          Friendly,

          salem@live.fr

          • 2. Re: Navigate between states
            bnther Level 1

            Thank you for the reply:)

             

            That looked pretty easy, much easier than what I'm used to...but it's not working.  Not sure why.  Is there any way to test something from a specific state?  I'd like to be able to run it from state 2 to see if it will work from there.

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                <mx:Script>
                    <![CDATA[
                        import mx.controls.*;
                        import mx.states.*;
                        private function basePage(event:Event):void{
                            currentState='';
                        }
                       
                        private function secondPage(event:Event):void{
                            currentState='2nd state';
                        }
                    ]]>
                </mx:Script>

             

                <mx:states>
                    <mx:State name="2nd state">
                        <mx:RemoveChild target="{button1}"/>
                        <mx:AddChild position="lastChild">
                            <mx:Button x="548" y="274" label="2nd state" click="basePage" id="button2"/>
                        </mx:AddChild>
                    </mx:State>
                </mx:states>
                <mx:Button x="461" y="273" label="base state" id="button1" click="secondPage"/>
               
            </mx:Application>

            • 3. Re: Navigate between states
              bnther Level 1

              Ooops!

               

              I forgot to put () after the mx click calls.  This is new to me.

              I'm still thinking that it's less keystrokes than straight up AS3.  At any rate I'm liking it.

               

              Thanks again.