4 Replies Latest reply on Oct 31, 2006 7:05 AM by peterent

    open component / mxml file + button click

    ljonny18 Level 1

      I am really struggling with my Flex application… I have looked on the internet and through the “macromedia flex” book itself, but am not having any joy understanding / finding a solution to my problem….

      I have put posts up on this forum and others but again have had no joy, I think it is because I am new to flex and am having difficulties explaining my problem and relating my query to a flex application rather than a website style application (which is what I am most familiar working with) etc……

      Anyway, enough of the ramble, I will try and explain again…

      I have a Flex application containing different MXML files acting as different “pages” within my application.. e.g. :


      my mainApp.mxml file is my main application file and shows / embeds the homepage.mxml file as the default “component”.
      Within my homepage.mxml file I have buttons (mx:button) labelled “view records” and “cotact us” etc…..

      1)when I click a button I want to show the relevant .mxml file (navigate to it) – so e.g. when the contact button is clicked I want to navigate to, and show the contact.mxml file within the application so I assume I need some sort of “click” event on the button, but I cant work out what!

      <mx:button id=”contactButton” label=”contact us” click=”show contact.mxml…….”/>

      2) additionally (in the case of the “view records” button) I want to also pass a variable (ID) as it changes across on the button click

      NOTE the ID is got and set from a dataGrid and saved as a bindable variable, so is already available and is ready in the application – I just need to pass it across into the viewRecords.mxml file

      If anyone could help, or offer any suggestions – it would be most appreciated.

        • 1. Re: open component / mxml file + button click
          peterent Level 2
          You said you have different MXML file acting as different "pages" - how are those files incorporated into the mainApp.mxml? Are they within a navigation container such as ViewStack or TabNavigator? They must be referenced in your mainApp.mxml file somehow or else the Flex compiler will not build them into the SWF it makes.

          <mx:ViewStack id="pages" .... >
          <local:homepage ... /> <!-- the index of this child is 0 -->
          <local:viewRecords ... />
          <local:contactPage ... /> <!-- the index of this child is 2 -->

          Now your button can switch "pages" (ie, child of the ViewStack, stack) like this:

          <mx:Button label="contact us" click="stack.selectedIndex=2" />
          • 2. Re: open component / mxml file + button click

            you need to bear in mind first that you're not actually going to open mxml files at runtime as they're compiled into swf files.

            You can either:

            use NavigatetoURL, there's an example in the help somewhere.

            Use swfLoader and/or a viewStack to create 'pages' inside your main app.

            Or similarly use States to create 'pages'.

            All quite easy to do.

            And there is also the popupManager...

            Depends really whether your app needs these as external files or not.


            • 3. Re: open component / mxml file + button click
              ljonny18 Level 1
              Hi peter,

              Yes I have different MXML files acting as different pages… these pages are currently incorporated into the mainApp.mxml file using a viewStack container – although, I don’t want all of these pages to be displayed within the viewStack….

              i.e. I only want for example the links: “homepage”, and “contact us” links to be in the viewstack, and for the “viewRecords.mxml” file to be accessed from a button click on the homepage etc…… - this is my problem.. Accessing files that are not initialized in the viewstack etc….

              • 4. Re: open component / mxml file + button click
                peterent Level 2
                If you don't want those components displayed in the ViewStack, then where do you want them to appear? In a PopUp? You have to have them referenced in some way.