4 Replies Latest reply on Aug 23, 2010 9:10 PM by jaya1685

    How to call one Main MXML from another main MXML file and pass values between them?

    jaya1685

       

      Hi,

      I am trying to populate a datagrid from a XML file ,which I have done successful

      I am able to get data out of the datagrid on clicking on any element

       

      Now when I click on any element in datagrid I want call a new mxml file which is also have Aplication tag and I want to pass that value of clicked element to it

       

      This is the code I am using for getting data from XML into data grid in 1st MXML file and the XML file used.

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"  initialize="exp.send()">
          
           <fx:Declarations>
               
               <s:HTTPService id="exp" url="expLab1.xml" result="

      resultHandlerQuestionBar(event)"/>
              
           </fx:Declarations>
          
          
           <s:Panel x="74" y="218" width="485" height="333" title="Work On Configured Experiments" id="p1" fontSize="14" chromeColor="#9BFDAB" dropShadowVisible="false" contentBackgroundColor="#E4EEE6" contentBackgroundAlpha="1.0" backgroundColor="#67B6AC" textAlign="left">
                <mx:DataGrid  x="35" y="33" width="338" height="88" dataProvider="{experimentdetails}" chromeColor="#FCFCFC" contentBackgroundColor="#FFFFFF" selectionColor="#FAFBFD" rollOverColor="#FCFDFF" focusColor="#FCFDFD" itemClick="onItemClick( event );">
                    <mx:columns>
                       <mx:DataGridColumn id="j1" dataField="experimentName" headerText="" itemRenderer="jaya">
                       </mx:DataGridColumn>
                    </mx:columns>
               </mx:DataGrid>
           </s:Panel>
          
          
           <fx:Script>
               <![CDATA[
                   import mx.collections.ArrayCollection;
                   import mx.controls.Alert;
                    import mx.events.FlexEvent;
                   import mx.events.ListEvent;
                   import mx.rpc.events.ResultEvent;
                  
                  
                   [Bindable]
                   private var workbenchname:ArrayCollection;
                    //private var a:String;
                   private function resultHandlerQuestionBar(event:ResultEvent):void
                   {
                      experimentdetails=event.result.List.experimentList.experiment;  
                   }
                  
                  
                   [Bindable]
                   private var experimentdetails:ArrayCollection;
                    private var alert:Alert;

      private var data:String;
                   private function onItemClick( e:ListEvent ):void {
                      

         data= experimentdetails.getItemAt(e.rowIndex).experimentName.toString();
                     
      alert=Alert.show(experimentdetails.getItemAt(e.rowIndex).experimentName.toString());
                      
                    }
               ]]>
           </fx:Script>
      </s:Application>

       

      and the xml file is:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <List>
         <workbench>Basic Movement</workbench>
           <experimentList>
             <experiment>
               <experimentName>Distance with varying time</experimentName>
               <Rating>2</Rating>
               <expNO>1</expNO>
              
             </experiment>
             <experiment>
               <experimentName>Distance with Constant time</experimentName>
               <Rating>1</Rating>
               <expNO>2</expNO>
              
             </experiment>
             <experiment>
               <experimentName>Time taken while decelerating</experimentName>
               <Rating>3</Rating>
               <expNO>3</expNO>
              
             </experiment>
            </experimentList> 
           
      </List>

       

       

      Now the code for 2nd MXML is as follows

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                           xmlns:s="library://ns.adobe.com/flex/spark"

                           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

            <fx:Declarations>

                  <!-- Place non-visual elements (e.g., services, value objects) here -->

            </fx:Declarations>

            <s:Label text="lable1" >

                 

            </s:Label>

      </s:Application>