2 Replies Latest reply on Jul 3, 2010 9:14 PM by ken_from_uk

    Newbie Question re showing new windows.

    ken_from_uk

      Im used to VB, where I could design several forms, for example start up with a splash screen, then unload that and load a login form, then hide that and display the main form etc.

       

      Im really struggling to figure out how you  get theld do the same in flexbuilder..

       

      How do you get the application to start with one 'form' then on a user event close that and open the main app?

       

      A simple example, say one page with just a text box and button on it that dwhen clicked opens a second app page with which shows the text entered on page one (ie how to pass variables accross forms)  it would help me out greatly to get my head around the concept in flex..

       

      Its just sooo different from what I am used to, im struggling with stuff that should really be easy, and feel a little silly

       

      can any one help out?

        • 1. Re: Newbie Question re showing new windows.
          djh88ukwb Level 1

          Hello,

           

          Flex makes use of different States.  You can define states using code similar to this.

           

              <s:states>
                  <s:State name="first"/>
                  <s:State name="second"/>
              </s:states>

           

          And then you can include certain components in certain states, or all states by using code similar to this

          <s:TextInput includeIn="first" x="25" y="45" width="298" id="name_txt"/>

           

          This will ensure that the textinput is only displayed on the first state, and not the second.  To allows it to be displayed on all states simply leave the includein statement out.

           

          You can then navigate through different states on user events by using a function such as

           

                      private function clicky():void
                      {               
                          currentState = "second";
                      }

           

          And then assigning a click attributes to a button or something similar

           

          <s:Button includeIn="first" x="138" y="87" label="Submit" click="clicky()"/>

           

          That will mean when the button is clicked the state being viewed changes from "first" to "second"

           

          Anyway, here is a quick example of asking for a name, and then swapping states on the button click, and displaying welcome + the name submitted.

           

          <?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" width="346" height="242">
              <s:states>
                  <s:State name="first"/>
                  <s:State name="second"/>
              </s:states>
              <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
             
              <fx:Script>
                  <![CDATA[           
                      private function clicky():void
                      {               
                          currentState = "second";
                          welcome_lbl.text = "Welcome " + name_txt.text;
                      }
                     
                  ]]>
              </fx:Script>
             
              <s:TextInput includeIn="first" x="25" y="45" width="298" id="name_txt"/>
              <s:Label includeIn="first" x="25" y="25" text="Enter Name" width="298" verticalAlign="middle" textAlign="center"/>
              <s:Button includeIn="first" x="138" y="87" label="Submit" click="clicky()"/>
              <s:Label includeIn="second" x="10" y="87" width="326" id="welcome_lbl" textAlign="center"/>
          </s:Application>

           

          Hope this helps

          • 2. Re: Newbie Question re showing new windows.
            ken_from_uk Level 1

            Thank you, that helped a great deal - I have now managed to figure out how it does it, and altered an example app I was working on to use stats. Thanks again, makes sense now.

             

            I did get a actionscript error (oddly only when I refreshed the page, not the first time it ran) 1009 - but I upgraded to the latest flash player and it works fine (that was withmy version of using the states).