4 Replies Latest reply on Jul 13, 2008 3:04 PM by ntsiii

    How to one mxml frm other mxml

      I need to know how to call one mxml from other mxml using addChild and removeChild Concept. Any one help me out.
        • 1. Re: How to one mxml frm other mxml
          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
          <mx:Button id="help" label="Hello" />

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"


          public var tute:test;
          public function init():void
          tute = new test();




          <mx:Button id="helps" label="Something" />

          • 2. Re: How to one mxml frm other mxml
            Thank-you. This worked.

            I took it a step further, and opened the component from a button.

            Close all existing projects by clicking the project and going FILE | CLOSE PROJECT. No, it won't go away.
            * Make a new project. Name it "TestNavigation04"
            * Into the Application file - in 'source' view - select everything and overwrite with the following code.

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

            public var objTestComponent:testComponent;

            public function loadMXMLtestComponent():void
            objTestComponent = new testComponent();

            <mx:Button id="helps" label="Something" click="loadMXMLtestComponent()" />

            * stop copying above this line
            * Save and close the application file
            * Create a component by going FILE |NEW|COMPONENT
            * Name this component "testComponent"
            * But a button onto the component.
            * Change the text of the button to "Testing Component"
            * Save and close the component.
            * Run the Application.

            (1) I got rid of the 'init'
            (2) Changed the variable name to objTestComponent - indicating it's an object based on the MXML
            (3) Changed the name of the function to "loadMXMLtestComponent" - more descriptive.
            (4) Changed the properties to reflect the new name for the object "objTestComponent"
            (5) Put a 'click' on the button, calling the function.

            ** I've seen too many people saying to put everything in one MXML - purchase order forms, sales forms - entire applications. This is just too much. Other suggested modules - but that is too much in the other direction.

            There has been very little on how to load different MXML files. Thanks to you, I have the starting point that I have seen scant information on - especially considering this is so basic.

            Thanks - I'm off and running.

            • 3. Re: How to one mxml frm other mxml
              ntsiii Level 3
              Yes, one big file and modules are the extremes.

              Normal flex apps are component based. A component can be a built-in component, like VBox, or can be a custom componetn implemented using either mxml or AS.

              Do not think in terms of "loading mxml files". Think in terms of instantiating components.

              Anywhere you use a tag in mxml, you can use a custom component. Anywhere you do "new" and addChild(), you can use a custom component. You can instantiate custom components under mx:Repeater.

              It is all components.

              • 4. Re: How to one mxml frm other mxml
                ntsiii Level 3
                There are two more major architectural options, loading independent application using SWFLoader, and navigating the browser using navigateToURL.