0 Replies Latest reply on Jul 11, 2007 3:48 PM by dex002

    XML to HorizontalList

    dex002
      Hi,

      I'm trying to build some HorizontalList components from a mx:model which calls an XML file. The list looks ok. It picks up the label field. However, I'm trying to access the 'price' property of each XML node so I can pass it to a function which builds the total price. I cannot figure out how to access the price property of each node. I have tried it lots of ways. Here is my code now, followed by the XML from the external XML file:


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

      <mx:Script>
      <![CDATA[

      private function buildTotal(selectionPrice:String):void{

      var price:Number = new Number(selectionPrice); //convert string to number
      trace(price);
      }

      ]]>
      </mx:Script>

      <mx:Model id="qModel" source="qXML.xml"/>

      <mx:Panel width="100%" height="100%" left="10" right="10" top="10" bottom="10">

      <mx:NumericStepper id="quantity" stepSize="5" minimum="5" maximum="50000"/>

      <mx:HorizontalList id="h1" dataProvider="{qModel.job}" click="buildTotal(qModel.job.price[h1.selectedIndex]);" columnCount="5" height="75" width="75%" rowHeight="150" columnWidth="100"/>

      <mx:HorizontalList id="h2" dataProvider="{qModel.disc}" click="buildTotal(qModel.job.price[h2.selectedIndex]);" columnCount="5" height="75" width="75%" rowHeight="150" columnWidth="100"/>

      <mx:TextArea id="totalText" text="" selectable="false" editable="false" borderThickness="0"/>

      </mx:Panel>

      </mx:Application>

      XML

      <?xml version="1.0"?>
      <catalog>

      <job>
      <label>CD</label>
      <image>project.png</image>
      <price>0</price>
      </job>

      <job>
      <label>DVD</label>
      <image>CD.swf</image>
      <price>0</price>
      </job>

      <job>
      <label>BlueRay</label>
      <image>CD.swf</image>
      <price>0</price>
      </job>

      <job>
      <label>CD 2</label>
      <image>CD.swf</image>
      <price>0</price>
      </job>

      <job>
      <label>DVD 2</label>
      <image>CD.swf</image>
      <price>0</price>
      </job>

      <disc>
      <label>Wide</label>
      <image>wide.swf</image>
      <price>1.00</price>
      </disc>

      <disc>
      <label>Wide</label>
      <image>wide.swf</image>
      <price>1.00</price>
      </disc>

      <disc>
      <label>Narrow</label>
      <image>wide.swf</image>
      <price>1.50</price>
      </disc>

      <disc>
      <label>Vinyl</label>
      <image>wide.swf</image>
      <price>1.75</price>
      </disc>

      <disc>
      <label>Small</label>
      <image>wide.swf</image>
      <price>2.00</price>
      </disc>

      <disc>
      <label>Big</label>
      <image>wide.swf</image>
      <price>3.00</price>
      </disc>

      <disc>
      <label>Silver</label>
      <image>wide.swf</image>
      <price>1.00</price>
      </disc>

      </catalog>