1 Reply Latest reply on Oct 5, 2007 7:20 AM by atta707

    ComboBox with multiple data?

      Please bear with me, I'm sure that this is very simple to answer and I will look quite stupid but I am new to Flex in fact I'm new to programing all together so treat me as some what of a simpleton.

      I'm trying to write a little application which is capable of calculating the weight of a publication. In order to do this I need to let the user type in the width and height so I can work out the total area. The application may be used by - how can I put it nicely "no technical" people so I needed to make it simple to use but with the ability for more advance users to type in the exact measurements.

      To provide this functionality I created two Numeric Steppers one for the width and one for the height, I also provided a Combobox which currently lists only A6, A5 and A4. If a user selects one of these options it changes the width and height values of the Numeric Steppers to the correct measurements for A6, A5 or A4.

      I do this with the following code (extract):

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

      import mx.collections.ArrayCollection;

      public var paperSizes:ArrayCollection = new ArrayCollection([{label:"A6",isoWidth:105,isoHeight:148},{label:"A5",isoWidth:148,isoHeig ht:210},{label:"A4",isoWidth:210,isoHeight:297}]);

      private function closeHandler(event:Event):void
      pageWidth.value = ComboBox(event.target).selectedItem.isoWidth;
      pageHeight.value = ComboBox(event.target).selectedItem.isoHeight;

      <mx:ComboBox x="10" y="10" width="157" id="stdPaperSizes" dataProvider="{paperSizes}" close="closeHandler(event);" selectedIndex="1"/>
      <mx:NumericStepper x="175" y="10" width="65" minimum="0" maximum="1000" stepSize="1" value="148" id="pageWidth"/>
      <mx:NumericStepper x="248" y="10" width="65" minimum="0" maximum="1000" stepSize="1" value="210" id="pageHeight"/>


      My question is am I using the ArrayCollection for the Combobox correctly, all the examples I have seen have something like ArrayCollection([{label:"Value1",data:1}]) all seem to have "data:" but this only passes one value I need to pass two values, the width and the height. Is this the correct way or is there a better way to do it? Although this works perfectly fine I hate to have invalid or incorrectly structured code.

      Many thanks in advance.