3 Replies Latest reply on Jun 19, 2009 4:17 PM by rtalton

    Assign .xml file to XML variable.

    WebmastaDj Level 1

      Here is what I want to do.  I want to assign an external XML file to the XML variable.  I already have an idea on how to do it, but not sure why it isn't working.  Here is script.as file:

      // ActionScript file
      import mx.rpc.events.ResultEvent;
      
      [Bindable]
      public var XMLData:XML;
      
      private function LoadXML(event:ResultEvent):void {
           XMLData = event.result();
           lblOutput.text = "successful - LoadXML";
      }
      
      private function AssignValues():void {
           lblOutput.text = XMLData.chipotle.(@name == "Chicken").calories;
      }
      
      private function LoadData():void {
           NutriData.send();
      }
      
      

       

      And here is my mxml file:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="700" height="500" currentState="NutriTable">
           <mx:Style source="style.css"/>
           <mx:Script source="script.as"/>
           <mx:states>
                <mx:State name="NutriTable" enterState="LoadData()">
                     <mx:AddChild position="lastChild">
                          <mx:Panel x="10" y="271" width="680" height="219" layout="absolute" title="Full Nutrition Table">
                               <mx:DataGrid x="0" y="0" width="660" height="179" dataProvider="{NutriData.lastResult.chipotle.menuitem}" id="table1">
                                    <mx:columns>
                                         <mx:DataGridColumn headerText="Name" dataField="name"/>
                                         <mx:DataGridColumn headerText="Calories" dataField="calories"/>
                                         <mx:DataGridColumn headerText="Calories From Fat" dataField="caloriesfromfat"/>
                                         <mx:DataGridColumn headerText="Total Fat" dataField="totalfat"/>
                                         <mx:DataGridColumn headerText="Saturated Fat" dataField="saturatedfat"/>
                                         <mx:DataGridColumn headerText="Trans Fat" dataField="transfat"/>
                                         <mx:DataGridColumn headerText="Cholesterol" dataField="cholesterol"/>
                                         <mx:DataGridColumn headerText="Sodium" dataField="sodium"/>
                                         <mx:DataGridColumn headerText="Carbohydrates" dataField="carbohydrates"/>
                                         <mx:DataGridColumn headerText="Dietary Fiber" dataField="dietaryfiber"/>
                                         <mx:DataGridColumn headerText="Sugars" dataField="sugars"/>
                                         <mx:DataGridColumn headerText="Protein" dataField="protein"/>
                                         <mx:DataGridColumn headerText="Vitamin A" dataField="vitamina"/>
                                         <mx:DataGridColumn headerText="Vitamin C" dataField="vitaminc"/>
                                         <mx:DataGridColumn headerText="Calcium" dataField="calcium"/>
                                         <mx:DataGridColumn headerText="Iron" dataField="iron"/>
                                    </mx:columns>
                               </mx:DataGrid>
                          </mx:Panel>
                     </mx:AddChild>
                     <mx:AddChild position="lastChild">
                          <mx:Panel x="10" y="30" width="680" height="233" layout="absolute" id="VariablePanel" title="Test Panel">
                               <mx:Label x="277.5" y="55" id="lblOutput" width="105" text="test" enabled="true"/>
                          </mx:Panel>
                     </mx:AddChild>
                </mx:State>
           </mx:states>
           <mx:HTTPService url="data.xml" id="NutriData" result="LoadXML(event)"></mx:HTTPService>
           <mx:MenuBar x="0" y="0" width="700"></mx:MenuBar>
      </mx:Application>
      
      

       

      I basically have an XML file with nutrition information in it and want to call the selected information and place it into a variable.  I think I have the concept of placing and searching the data via XML object type but don't know how to get the XML data into the XML object variable?