3 Replies Latest reply on Jan 12, 2010 11:43 AM by Gregory Lafrance

    how can access every item on a HorizontalList Component

    sebastiantoro84 Level 1

      Hi,

             I would like to know how can I access every item on a HorizontalList component. What I want to do is something like this:

       

      My HorizontalList:

       

      <mx:HorizontalList
              bottom="0"
              backgroundAlpha="0.0"
              id="catalogoOpciones"
              columnCount="3"
              height="80"
              hideEffect="{esconderse}"
              horizontalScrollPolicy="on"
              selectable="false"
              showEffect="{mostrarse}"
              width="100%">
              <mx:itemRenderer>
                  <mx:Component>
                      <mx:VBox  height="100%" verticalGap="0" horizontalAlign="center">
                          <mx:Label id="titulo" text="{data.nombre}"  textAlign="center" styleName="nombreOpcionDetallePlato" />
                          <mx:ComboBox id="seleccion" dataProvider="{data.opciones}" labelField="label" labelFunction="funcionLabelComboBox"                                         styleName="comboOpcionDetallePlato" change="dispatchEvent(new Event('cambioOpcion',true))"/>
                          <mx:Script>
                              <![CDATA[
                                  public function funcionLabelComboBox(item:Object):String {
                                          return item.label + ", $" + item.precio;
                                  }
                              ]]>
                          </mx:Script>
                      </mx:VBox>               
                  </mx:Component>
              </mx:itemRenderer>
          </mx:HorizontalList>

       

      What I want to do is to show on an Alert screen the selected index in every ComboBox on the horizontallist:

       

      for(var i:Number=0;i<horizontalListt.dataProvider.length;i++){
           var indice:Number = (horizontalListt.dataProvider.getChildAt(i) as ComboBox).selectedIndex;
          Alert.show(indice.toString());

      }

       

      I must add, that the horizontalList is working just fine, the only thing that's giving me problems is the access to every item in the list.

       

      Thank you very much for your time and help.

       

      Sebastián Toro O.

        • 1. Re: how can access every item on a HorizontalList Component
          Gregory Lafrance Level 6

          The data provider should contain a field for the item's selected index. When the user selects a different item in the ComboBox, change the data in the data provider.

           

          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          • 2. Re: how can access every item on a HorizontalList Component
            sebastiantoro84 Level 1

            Greg, thank you for your quick response, but your answer is a little ambiguous for me. How can my dataProvider change when the user selects another index? the itemRenderer it's supposed get the information off the dataProvider to fill its ComboBoxes, but when the user selects another index, that change shouldn't have any effect on the dataProvider.

             

            remember that the itemRenderer is:

             

            <mx:itemRenderer>
                        <mx:Component>
                            <mx:VBox  height="100%" verticalGap="0" horizontalAlign="center">
                                <mx:Label id="titulo" text="{data.nombre}"  textAlign="center" styleName="nombreOpcionDetallePlato" />
                                <mx:ComboBox id="seleccion" dataProvider="{data.opciones}" labelField="label" labelFunction="funcionLabelComboBox"                                                   styleName="comboOpcionDetallePlato"  change="dispatchEvent(new Event('cambioOpcion',true))"/>
                                <mx:Script>
                                    <![CDATA[
                                        public function funcionLabelComboBox(item:Object):String {
                                                return item.label + ", $" + item.precio;
                                        }
                                    ]]>
                                </mx:Script>
                            </mx:VBox>               
                        </mx:Component>
                    </mx:itemRenderer>

             

            So what I whant to access, is every Component that the itemRenderer created:

             

            Alert.show(((catalogoOpciones.dataProvider.getItemAt(0) as VBox).getChildByName("seleccion") as ComboBox).selectedIndex.toString());

             

            I want to get the selectedIndex of the ComboBox of the First Item that was created on the  HorizontalList. I thought the last line of code would do the trick but it doesn't. Could you be more specific please?

             

            Thanks again

             

            Sebastián Toro O.

             

            PS:don't worry that if you answer my question you'll get the 10 pts

            • 3. Re: how can access every item on a HorizontalList Component
              Gregory Lafrance Level 6

              You usually (very close to always) want to change the dataProvider data when items in list based components change. The change handler for the ComboBox should do this. List based components recycle their item renderers, so you have to go to the data.