6 Replies Latest reply on Feb 21, 2008 6:50 AM by SiHoop

    Linking to mxml files

    SiHoop Level 1
      I've created a login that will send users in 1 of 3 direction (i.e.administrator, teacher, or student). I want each type of user to link to a separate mxml file because, if I use States, my file will become quite large and I don't want to have to navigate through long files when I'm coding.

      My question: How do I link to an another mxml file from the main.mxml file?
      Thanks!
        • 1. Re: Linking to mxml files
          jfillman Level 1
          Take a look at modules. Load a different module based on who logs in.
          • 2. Re: Linking to mxml files
            SiHoop Level 1
            Thanks for the reply-- using modules seems to work, but they also seem to be very unsophisticated. This is not meant as a criticism of your reply, but I do think it's a limitation of Flex.
            • 3. Re: Linking to mxml files
              Gregory Lafrance Level 6
              How about a ViewStack:

              ------------------------------ ViewStack.mxml -------------------------------
              <?xml version="1.0"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:comp="components.*">
              <mx:Script>
              <![CDATA[
              private function selectPortal(event:Event):void {
              if(cmbx.selectedItem.data == "home"){
              portals.selectedChild = home;
              }
              if(cmbx.selectedItem.data == "hr_portal"){
              portals.selectedChild = hr_portal;
              }
              if(cmbx.selectedItem.data == "is_portal"){
              portals.selectedChild = is_portal;
              }
              if(cmbx.selectedItem.data == "pay_portal"){
              portals.selectedChild = pay_portal;
              }
              }
              ]]>
              </mx:Script>

              <mx:ApplicationControlBar width="100%">
              <mx:Label text="Select an intranet portal: " fontSize="12"/>
              <mx:ComboBox id="cmbx" change="selectPortal(event)">
              <mx:Object label="XYZ Intranet Home Page" data="home"/>
              <mx:Object label="Human Resources Portal" data="hr_portal"/>
              <mx:Object label="Information Services Portal" data="is_portal"/>
              <mx:Object label="Payroll Portal" data="pay_portal"/>
              </mx:ComboBox>
              </mx:ApplicationControlBar>
              <mx:ViewStack id="portals" width="100%" height="100%">
              <mx:Panel width="100%" height="100%" horizontalAlign="center"
              backgroundColor="#ccffcc" id="home">
              <mx:Text text="Welcome to the XYZ Corporate Intanet" fontSize="20"
              color="blue"/>
              </mx:Panel>
              <comp:HumanResources id="hr_portal"/>
              <comp:InformationServices id="is_portal"/>
              <comp:Payroll id="pay_portal"/>
              </mx:ViewStack>
              </mx:Application>
              ------------------------------------------------------------------------------------
              ---------- components/HumanResources.mxml ------------------
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Panel xmlns="*" xmlns:mx=" http://www.adobe.com/2006/mxml"
              width="100%" height="100%" horizontalAlign="center" backgroundColor="red">
              <mx:Text text="Human Resources Portal" fontSize="20"
              color="blue"/>
              </mx:Panel>
              ------------------------------------------------------------------------------------
              ---------- components/InformationServices.mxml ------------------
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Panel xmlns="*" xmlns:mx=" http://www.adobe.com/2006/mxml"
              width="100%" height="100%" horizontalAlign="center" backgroundColor="purple">
              <mx:Text text="Information Services Portal" fontSize="20"
              color="blue"/>
              </mx:Panel>
              ------------------------------------------------------------------------------------
              ---------- components/Payroll.mxml ------------------
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Panel xmlns="*" xmlns:mx=" http://www.adobe.com/2006/mxml"
              width="100%" height="100%" horizontalAlign="center" backgroundColor="gray">
              <mx:Text text="Payroll Portal" fontSize="20"
              color="blue"/>
              </mx:Panel>
              • 4. Re: Linking to mxml files
                SiHoop Level 1
                Greg,
                First, thanks for your reply. I tried the following, but as you will see, got an error message.
                I created a Flex Project file titled ViewStack.mxml, stored in the src folder. Next, I created a folder titled 'components' and added 3 MXML Component files to this folder and named the files HumanResources.mxml, InformationServices.mxml, and Payroll.mxml.

                When I did this I received 3 errors (one for each of the component files. Here's the first error:
                1046: Type was not found or was not a compile-time constant: HumanResources

                Please tell me if I am doing something wrong.
                Thanks!
                • 5. Re: Linking to mxml files
                  Gregory Lafrance Level 6
                  All the component mxml files should be in a sub-folder "components" of the folder containing ViewStack.mxml so:

                  ProjectFolder
                  --- ViewStack.mxml
                  --- components
                  ------ HumanResources.mxml
                  ------ InformationServices.mxml
                  ------ Payroll.mxml
                  Also ensure xmlns:comp="components.*" is in the code as I am using it.
                  • 6. Re: Linking to mxml files
                    SiHoop Level 1
                    That's perfect, thank you! My error was to place the components folder at the wrong level.