3 Replies Latest reply on Apr 16, 2010 10:29 AM by Shongrunden

    Spark HList ItemRenderer

    daslicht Level 2

      Hello,

      I have a external ItemRenderer for a Spark List which displays only one Item.

       

      How do I get that Item and its including data.

       

      At the moment I use getChildAt and Cast it as a Instance of the Item Renderer.

       

      eg:

      var temp:HListRenderer = myList.getChildAt( myList.selectedIndex ) as HListRenderer;
          temp.varToAccess = 'cool';

       

      Is there a smarter way to do this ?

      How to access the visible Item of a <s:HList/> ? In that case I could negelect the whole get ChildAt approach.

       

      Cheers

      Marc

        • 1. Re: Spark HList ItemRenderer
          David_F57 Level 5

          hi,

           

          there is this mylist.dataGroup.getItemIndicesInView() - saw this in an earlier post that shongrunden(adobe) answered.

           

          I know there is a call to get the first and last items in a view but for the life of me I can't find it, I might have to pester one of the Adobe guys

           

          David.

          • 2. Re: Spark HList ItemRenderer
            Flex harUI Adobe Employee

            The layout should have a firstIndexInView and lastIndexInView

            • 3. Re: Spark HList ItemRenderer
              Shongrunden Adobe Employee

              Here is a sample application based on the sample provided in http://forums.adobe.com/message/2731455

              <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark">
                 
                  <fx:Script>
                      <![CDATA[
                          public function getData():void {
                         
                               var indicesInView:Vector.<int> = list1.dataGroup.getItemIndicesInView();
                              
                               for (var i:int = 0; i < indicesInView.length; i++){
                                  var dataItem:* = list1.dataProvider.getItemAt(indicesInView[i]);
                                  trace('data at index ', indicesInView[i], ' = ', dataItem);
                               }
                          }
                      ]]>
                  </fx:Script>
                 
                  <s:controlBarContent>
                      <s:Button label="increment vsp" click="list1.dataGroup.verticalScrollPosition+=22" />
                      <s:Button label="trace data of items in view" click="getData()" />
                  </s:controlBarContent>
                 
                  <s:List id="list1" width="100" height="18">
                      <s:dataProvider>
                          <s:ArrayList>
                              <fx:String>a</fx:String>
                              <fx:String>b</fx:String>
                              <fx:String>c</fx:String>
                              <fx:String>d</fx:String>
                              <fx:String>e</fx:String>
                              <fx:String>f</fx:String>
                              <fx:String>g</fx:String>
                              <fx:String>h</fx:String>
                          </s:ArrayList>
                      </s:dataProvider>
                  </s:List>
                 
              </s:Application>