0 Replies Latest reply on Oct 25, 2006 4:24 AM by ljonny18

    Passing variables between MXML files / components

    ljonny18 Level 1
      Hi

      I am having difficulty with my Flex Application… I don’t know if I am just being stupid and missing / mi-understanding something (which is probably the case) but thing don’t seem to be going my way :(

      My application is quite large now, so I will try and explain / include much summarised detail and code examples.


      Basically, I have my main MXML File which includes an applicationControlBar containing a linkBar populated using a viewStack as its dataProvider….
      The application navigator “links” to other components (MXML files) within the application that are stored in a “components” folder:

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

      <mx:ApplicationControlBar id="appBar_apc" dock="true">
      <mx:LinkBar dataProvider="MenuObjects_lb"/>
      </mx:ApplicationControlBar>

      <mx:ViewStack id="MenuObjects_lb">

      <mi:homePage id="home_page" label="Homepage"/>
      <mi:search id="Search" label="Search"/>
      <mi:manageUsers id="manage_usrs" label="Manage Users"/>
      <mi:viewOPG id="view_OPG" visible="false"/>

      </mx:ViewStack>
      </mx:Application>


      The 1st page the user sees is the “Homepage” this page contains a dataGrid that is provided data from a webService – calling the webService and setting up a dataProvider accordingly to populat the dataGrid etc….
      The data provided from the dataProvider comes originally from a database and each row contains a unique ID.
      The data is displayed in the dataGrid ok, and the ID is assigned ok, and when a row of the dataGrid is selected the correct ID of the selected row is taken – so all is ok to this point:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:mi="components.*">

      <mx:Script>
      <![CDATA[
      public function handleWSR(event:ResultEvent):void
      {
      myDG.dataProvider = event.result;
      }

      public function dgItemSelect():void
      {
      selectedID = myDG.selectedItem.id;
      //Alert.show(selectedID);
      }
      ]]>
      </mx:Script>

      <mx:WebService id="wsData" wsdl=" http://...?wsdl">
      <mx:operation name="getData" result="handleWSR(event)"/>
      </mx:WebService>

      <mx:Panel id="home_page_test" title="Homepage Test">
      <mx:Form>

      <mx:DataGrid id="myDG" change="dgItemSelect()">
      <mx:columns>
      <mx:DataGridColumn id="id" dataField="id" headerText="ID"/>
      <mx:DataGridColumn dataField="a" headerText="A"/>
      <mx:DataGridColumn dataField="b" headerText="B"/>
      <mx:DataGridColumn dataField="c" headerText="C"/>
      <mx:DataGridColumn dataField="D" headerText="D"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Button id="viewItem" label="View Selected Item" click="????"/>

      </mx:Form>
      </mx:VBox>
      </mx:Panel>
      </mx:VBox>

      as you can see – beneath my dataGrid is a button (View) which when clicked I want to take the ID of the selected dataGrid row and pass this ID to another MXML file / component (viewRow.mxml) within my application.
      When the “viewRow.mxml” is opened / called I want it to take the ID that was selected from the previous mxml component (the homepage) and use it in another webService call (send the ID to a webService which then uses the ID to retrieve data that is relevant to that ID and thus pass it back to the component) using and displaying the results accordingly…..

      Mmmm, I hope that makes sense?

      Like I say, I am having great difficulty passing variable from one MXML file to another allowing such dynamic operations – passing and retrieving variables between components (displaying data relevant to a selected ID from another components etc…)
      I don’t know if I am doing something wrong (I am quite new to Flex and this is my first “real” Flex application), hence I am asking for some advice, so any suggestions / advice on this would be much appreciated.

      Thanks,
      Jon.