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

    How to one mxml frm other mxml

    Muthu_cool Level 1
      Hi,
      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
          FlexPrashant
          test.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" />
          </mx:Application>
          Text

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




          <mx:Script>
          <![CDATA[

          public var tute:test;
          public function init():void
          {
          tute = new test();
          tute.x=50;
          tute.y=100;

          this.addChild(tute);

          }


          ]]>
          </mx:Script>

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


          </mx:Application>
          • 2. Re: How to one mxml frm other mxml
            DaGunster_
            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">

            <mx:Script>
            <![CDATA[
            public var objTestComponent:testComponent;

            public function loadMXMLtestComponent():void
            {
            objTestComponent = new testComponent();
            objTestComponent.x=50;
            objTestComponent.y=100;
            this.addChild(objTestComponent);
            }
            ]]>
            </mx:Script>

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

            * 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.

              Tracy
              • 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.

                Tracy