4 Replies Latest reply on May 17, 2011 3:58 AM by _spoboyle

    VirtualLayout goToItem

    _spoboyle Level 4

      I have a DataGroup that taht does not use virtualLayout each item in the group has a date property and I can force the group to scroll to an item by traversing all the item until I find the one with the correct date.


      Now I want to change this DataGroup to use virtualLayout instead. However now when I tranverse the items the ones not currently being displayed are null. I am also thinkign that even if they weren't the y property of these items (which i use to set the containing scrollbar scroll position) will probably not be correct.


      Can anyone suggest a way of achieving this?

        • 1. Re: VirtualLayout goToItem
          saisri2k2 Level 4



          EDIT: Yikes.. din see that it was Datagroup !!!! Ignore!!


          Message was edited by: saisri2k2

          • 2. Re: VirtualLayout goToItem
            saisri2k2 Level 4
               public function ensureIndexIsVisible(index:int):void
                    if (!layout)
                    var spDelta:Point = dataGroup.layout.getScrollPositionDeltaToElement(index);
                    if (spDelta)
                        dataGroup.horizontalScrollPosition += spDelta.x;
                        dataGroup.verticalScrollPosition += spDelta.y;

            I see this implementation in the spark list for scrolling to the position, it might help you.

            1 person found this helpful
            • 3. Re: VirtualLayout goToItem
              _spoboyle Level 4

              close, I have to call that function 3-4 times before it works the first time and once it works I only have to call it once each time I want to show a different element in the DataGroup


              CORRECTION: the function works but only works for elements at the bottom of the DataGroup after the scrollbar has scrolled to the bottom once

              • 4. Re: VirtualLayout goToItem
                _spoboyle Level 4

                Looking at VerticalLayout.getElementBounds() the documentation says:



                Layout subclasses that support useVirtualLayout=true must override this method to compute a potentially approximate value for elements that are not in view.



                can anyone confirm that this is what is causing my issue since each row in my DataGroup is not a fixed height?

                Since VerticalLayout supports variable row height does this mean that ensureElementIsVisible cannot work in these circumstances?


                EDIT: I am now certain that the problem is caused by layout.getElementBounds() not returning the correct values. My suspision is that by scrolling to the bottom of the list before trying to navigate to any particular index allows the actual height of the various rows to be calculated.