6 Replies Latest reply on Jan 14, 2010 4:36 PM by David_F57

    can a flex project have multiple mxml files ?

    dacquah

      can a flex project have multiple mxml files ?

      that means, muliple mx:Application..

       

      if so, how do we navigate through these different mx:Application ?

       

      what option can we use besides: 

      navigateToURL(

      new URLRequest(...   ?

        • 1. Re: can a flex project have multiple mxml files ?
          Gregory Lafrance Level 6

          In a strict sense, you usually have one MXML file per Flex project with Application as the root tag.

           

          But you can have multiple MXML applications in a Flex project, its up to you from a design perspective.

           

          You can connect between applications with LocalConnection.

           

          http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_4 .html

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: can a flex project have multiple mxml files ?
            dacquah Level 1

            thx for your response...

             

            if i have 1 mx:Application for my project... and I have lets say, 20 different screens.....

            I can use ViewStates etc.. to navigate between different screens, but that will make my mxml file very huge...

             

            so i wanted to put all code for each screen into its own mxml file...

            if there was a way i could include or reference an mxml file from within another mxml file, just as we do for

            including an external as - action script file, then i could break my project into multiple files...

             

            as it is now, i have 20 screens so 20 view states, with a canvas in each of them... so my mxml is getting too huge

            any suggestions ?>

            • 3. Re: can a flex project have multiple mxml files ?
              David_F57 Level 5

              Hi,

               

              You should always break your project up into logic 'modules' there are many ways that this can be done for the simplest way each 'screen' is a mxml file based on group (basically a component), Obviously once you modularise your application there will be the additional overhead of how information is passed through the hierarchy. But the following should getting you started with having separate screens.

               

               

              David.

               

              the application

              ===========

              <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>

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

                 xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;

                 xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot; minWidth=&quot;955&quot; minHeight=&quot;600&quot; xmlns:ns1=&quot;*&quot;>

              <fx:Declarations>

              <!-- Place non-visual elements (e.g., services, value objects) here -->

              </fx:Declarations>

              <s:states>

              <s:State name=&quot;Screen1&quot;/>

              <s:State name=&quot;Screen2&quot;/>

              </s:states>

              <s:Button x=&quot;10&quot; y=&quot;10&quot; label=&quot;Screen1&quot; click=&quot;currentState=&quot;Screen1&quot;&quot;/>

              <s:Button x=&quot;104&quot; y=&quot;10&quot; label=&quot;Screen2&quot; click=&quot;currentState=&quot;Screen2&quot;&quot;/>

              <ns1:Screen1 includeIn=&quot;Screen1&quot; x=&quot;532&quot; y=&quot;277&quot;>

              </ns1:Screen1>

              <ns1:Screen2 includeIn=&quot;Screen2&quot; x=&quot;578&quot; y=&quot;283&quot;>

              </ns1:Screen2>

              </s:Application>

               

               

              Screen1.mxml

              ===========

              <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
              <s:Group xmlns:fx=&quot;http://ns.adobe.com/mxml/2009"
              xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
              xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot; width=&quot;400&quot; height=&quot;300&quot; verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot;>
              <s:Button x=&quot;75&quot; y=&quot;120&quot; label=&quot;Button&quot;/>
              <s:CheckBox x=&quot;200&quot; y=&quot;53&quot; label=&quot;CheckBox&quot;/>
              <s:CheckBox x=&quot;200&quot; y=&quot;116&quot; label=&quot;CheckBox&quot;/>
              <s:CheckBox x=&quot;200&quot; y=&quot;181&quot; label=&quot;CheckBox&quot;/>
              </s:Group>
              Screen2.mxml
              ===========
              <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?>
              <s:Group xmlns:fx=&quot;http://ns.adobe.com/mxml/2009"
              xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
              xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot; width=&quot;400&quot; height=&quot;300&quot; verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot;>
              <s:Button x=&quot;57&quot; y=&quot;230&quot; label=&quot;Button&quot;/>
              <s:Button x=&quot;57&quot; y=&quot;41&quot; label=&quot;Button&quot;/>
              <s:Button x=&quot;61&quot; y=&quot;121&quot; label=&quot;Button&quot;/>
              <mx:ProgressBar x=&quot;165&quot; y=&quot;230&quot;/>
              <mx:PopUpButton x=&quot;213&quot; y=&quot;41&quot; label=&quot;PopUpButton&quot;/>
              <s:RadioButton x=&quot;213&quot; y=&quot;97&quot; label=&quot;Radio&quot;/>
              </s:Group>

              • 4. Re: can a flex project have multiple mxml files ?
                David_F57 Level 5

                Oops, looks like the forum chewed up the mxml

                 

                 

                http://ezflex.net/modular/

                 

                 

                go here for the code - (rightclick provides source)

                 

                 

                David

                • 5. Re: can a flex project have multiple mxml files ?
                  Daniel Pride Level 1

                  Thanks for the source code links. but if you have an app with say 50 screens (about the average of the old client server apps), and you use states then everything loads at once does it not? Is there a better way to do this? I understand viewstacks don't load their content until asked for, but then you still wind up with a long list of stacks as a home mxml screen. Isn't there a way to programatically call components?

                   

                  Dan Pride

                  • 6. Re: can a flex project have multiple mxml files ?
                    David_F57 Level 5

                    Hi Dan,

                     

                    As I said in my earlier response, there are several ways to 'modularise' an application.

                     

                    States work in a similar way to viewstacks, components are not 'instantiated' until they are added to the displaylist, just like viewstacks if you need access to something in a state before its displayed you need to set its creation policy. I slapped together the state example as that was the question asked by the originating poster(its my speciality quick 'n dirty code ).

                     

                    In a large complex project you could use modules which are individual swf's so they are loaded only when you need them, you would still probably use viewstacks or states in these modules as it is more common to have groups of screens, for example I have an app with 160 screens one particular module has about 25 screens the other modules vary from 3-10 screens.

                     

                    At the end of the day its about finding balance and when it comes to balance the biggest part of that balance(after you ignore project bean counters) is the user experience, if its an application that gets used by the end user rarely then it needs to download reasonably quickly each and every time and no noticable lag when changing screens so separate modules are probably not the best option. If its an app that is used on a regular basis then runtime libraries and optimised modules are the way to go, the user has the extra bit of time to wait when running the app the first time and minor lag between screens but its blindingly fast the next time they use it.

                     

                     

                     

                    David