6 Replies Latest reply on Aug 19, 2008 7:27 AM by joshua.java

    How to move to another mxml component?

    joshua.java
      Dear all,

      I have an mxml component that is embedded in MXML application. Now I want to call another mxml component from that component, how do I do that in Flex? What I want is like opening a new HTML page with <a>? How is this done in Flex? Could anyone give me a hint on this please?

      Many thanks
        • 1. How to move to another mxml component?
          Arun_B
          Hello Joshua,
          If I understood your question correctly, you can do this but putting the component you want to invoke inside a ViewStack and then redirect to that component based on the selectedIndex value.In the example below, each view is a MXML component.

          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:business="com.psod.selfservice.business.*" xmlns:control="com.psod.selfservice.control.*" xmlns:salesforce="com.salesforce.*"
          xmlns:view="com.psod.selfservice.view.*"
          layout="vertical" backgroundColor="#FFFFFF" width="1545" height="929">

          <mx:ViewStack width="100%" height="100%" paddingBottom="10" paddingTop="10" resizeToContent="true" selectedIndex="{_amLocator.nViewing}">
          <view:SSPLoginPage />
          <view:CustomerPortal/>
          <view:ThankYou/>
          <view:ProjectDetView/>
          </mx:ViewStack>
          </mx:Application>

          I would suggest you to browse the examples of viewstack to learn more on this.
          • 2. Re: How to move to another mxml component?
            joshua.java Level 1
            quote:

            Originally posted by: Arun B
            Hello Joshua,
            If I understood your question correctly, you can do this but putting the component you want to invoke inside a ViewStack and then redirect to that component based on the selectedIndex value.In the example below, each view is a MXML component.

            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:business="com.psod.selfservice.business.*" xmlns:control="com.psod.selfservice.control.*" xmlns:salesforce="com.salesforce.*"
            xmlns:view="com.psod.selfservice.view.*"
            layout="vertical" backgroundColor="#FFFFFF" width="1545" height="929">

            <mx:ViewStack width="100%" height="100%" paddingBottom="10" paddingTop="10" resizeToContent="true" selectedIndex="{_amLocator.nViewing}">
            <view:SSPLoginPage />
            <view:CustomerPortal/>
            <view:ThankYou/>
            <view:ProjectDetView/>
            </mx:ViewStack>
            </mx:Application>

            I would suggest you to browse the examples of viewstack to learn more on this.



            Thanks Arun,

            But my question really is: How do I move from SSPLoginPage by clicking a LinkButton inside SSPLoginPage into another component ProjectDetView? Have you ever been into that situation before?

            Many thanks
            • 3. Re: How to move to another mxml component?
              cathyshapiro
              Hi Joshua,

              The way I do it is handle the link from the main application.

              Create a function in the main application like this:

              public function gotoComponent(myEvent:String):void
              {
              {viewstack1.selectedChild=OtherComponent};
              }

              then in the component do something like:

              <mx:LinkButton id="myLinkBtn" label="Link to other component" click="{Application.application.gotoComponent(MouseEvent.CLICK)}"/>

              Hope that helps,
              Cathy
              • 4. Re: How to move to another mxml component?
                cathyshapiro Level 1
                Oh, one thing I forgot to mention is make sure you import the application class on the component so you can refer back to the application.

                import mx.core.Application;

                Cathy
                • 5. Re: How to move to another mxml component?
                  joshua.java Level 1
                  quote:

                  Originally posted by: cathyshapiro
                  Oh, one thing I forgot to mention is make sure you import the application class on the component so you can refer back to the application.

                  import mx.core.Application;

                  Cathy


                  Thanks Cathy. I'm going to try it out. :) Really helpful.

                  Best regards,

                  • 6. Re: How to move to another mxml component?
                    joshua.java Level 1
                    I have to use viewStack.selectedIndex as viewStack.selectedChild as shown in your example works. Perhaps I have missed on something.

                    Thanks!