4 Replies Latest reply on Aug 25, 2010 8:22 AM by Boy Carper

    Creating a list with a dynamic counter

    iamcootis Level 1

      I have a dataProvider that looks like this.

      <dataProvider>

           <Array>

       

                <Object>Apples</Object>

                <Object>Oranges</Object>

                <Object>Bananas</Object>

                <Object>Limes</Object>

       

           </Array>

      </dataProvider>

       

      I want to be able to display those items in a list with a counter like...

       

      1. Apples

      2. Oranges

      3. Bananas

      4. Limes

       

      What is the best way to go about doing this?

        • 1. Re: Creating a list with a dynamic counter
          John Hall Level 4

          Might need a little more detail. Which version of Flex? Are you outputting to a textarea or is this the dataprovider for a list or some other control? If not a dataProvider for a specific control, is there a reason you prefer MXML for the dataProvider model (nothing wrong with it just curious what you're trying to accomplish and wondering if it might be better to do it in ActionScript if it's coming from an external source).

          • 2. Re: Creating a list with a dynamic counter
            BhaskerChari Level 4

            Hi Cootis,

             

            Hope this is the best way possible to acheive it...

             

            <?xml version="1.0"?>
            <!-- Simple example to demonstrate the PieChart control. -->
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" width="100%">
                <mx:Script>
                    <![CDATA[
                   
                    ]]>
                </mx:Script>
              <mx:XML id="myXml" xmlns="">
                <dataProvider>
                  <Array>
                   <Object>Apples</Object>
                   <Object>Oranges</Object>
                   <Object>Bananas</Object>
                   <Object>Limes</Object>
                  </Array>
              </dataProvider>
              </mx:XML>
             
              <mx:List id="myList" dataProvider="{myXml.Array.Object}">
               <mx:itemRenderer>
                <mx:Component>
                 <mx:Label>
                  <mx:Script>
                       <![CDATA[
                        public override function set data(value:Object):void
                        {
                         super.data = value;
                         text = (listData.rowIndex + 1) + ". " + value;
                        }
                       ]]>
                   </mx:Script>
                 </mx:Label>
                </mx:Component>
               </mx:itemRenderer>
              </mx:List>
                         
            </mx:Application>

             

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


            Thanks,

            Bhasker Chari

            • 3. Re: Creating a list with a dynamic counter
              iamcootis Level 1

              I am using Flex 4 and the list isn't in MXML it's dynamic and in an arrayCollection. I was just trying to give an example. And this is going to be displayed in a <s:List>

               

              Thanks.

              • 4. Re: Creating a list with a dynamic counter
                Boy Carper

                Check out this example.

                 

                You can add the index of the element in the customItemRenderer, see this example