6 Replies Latest reply on Jun 22, 2009 5:10 AM by L.A.D.

    Automatically jump to the end of a HorizontalList?

    L.A.D.

      Hi

       

      I've been banging my head against the wall with this.

       

      I want to create a horizontal list, that when the scroll bars are visible, jumps automatically to the last item in the list  - making sure that the last item is fully visible, and updates automatically when the dataprovider is changed. Can anyone help me out with this one?

       

      I managed to get something working for this using maxHorizontalScrollPosition, but the last item in the list was never fully visible

       

      Thanks in advance

        • 1. Re: Automatically jump to the end of a HorizontalList?
          Flex harUI Adobe Employee

          scrollToIndex?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Automatically jump to the end of a HorizontalList?
            L.A.D. Level 1

            Been trying that but keep getting a very odd error

             

            my code looks like a bit like this

             

            var tryFilterSource:ArrayCollection = new ArrayCollection(tryHistoryArray);
                            
            tryFilterSource.filterFunction = filterByLevel;
            tryFilterSource.refresh()

             

            historyList.dataProvider = tryFilterSource;

            historyList.scrollToIndex( tryFilterSource.length - 1);

             

            if I use scrollToIndex i get an "null reference" error from my custom itemrenderer - but don't get the itemRenderer error  if I remove the call to  scrollToIndex, if i run traces on the variables that are featured in the lines reported as the source of the error all the variables seem fully polulated with data?!?!?!

            • 3. Re: Automatically jump to the end of a HorizontalList?
              L.A.D. Level 1

              Doh me... realised that I need to check if the arraycollection was greater than 0 before trying to scroll to it

               

              this fix the null reference

               

              if(tryFilterSource.length > 1)
              {
                     historyList.scrollToIndex(tryFilterSource.length - 1);
              }

               

              I've still had a few problems with the scrolling however, if an item renderer is only partial visible it doesn't jump fully into view, I really need for the last item to be fully visibable.

               

              see pic

              • 4. Re: Automatically jump to the end of a HorizontalList?
                Flex harUI Adobe Employee

                Hmm.  That might be a bug, but maybe if you're adding a new item the list hasn't updated its maxHorizontalScrollPosition yet.  Try calling historyList.validateNow() before calling scrollToIndex

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 5. Re: Automatically jump to the end of a HorizontalList?
                  L.A.D. Level 1

                  Thanks Alex for the suggestion.

                   

                  Unfortunately the first time the scroll bars appear the item on the far right is still only slightly visible and not in full view even after validateNow() is called

                  • 6. Re: Automatically jump to the end of a HorizontalList?
                    L.A.D. Level 1

                    Ended up creating something of a work around for this bug.

                     

                    I had originally used constraints based postioning to control the size of the list, so  -  left="20"  and right="20" - to ensure the list had a border of 20 pixels on each size. This way the list would have expanded to fit whatever space was available.  Doing it this way is when I have the probs with the item as mentioned above.

                     


                    However I removed the constraints based layout attributes and placed a listener on the parent container of the list to listen for it to resize

                     

                    mainContainer.addEventListener(ResizeEvent.RESIZE, changeHistoryListToFit)

                     

                    I then wrote a function that update the columns visible on the HorizontalList each time the  parent container was resized

                     

                    private function changeHistoryListToFit(event:ResizeEvent):void
                    {
                            var historyColCount:Number = Math.floor((mainContainer.width - 40) /  historyList.columnWidth);
                            if(historyColCount > 2 && (historyColCount != historyList.columnCount))
                            {
                                    historyList.columnCount = historyColCount;
                                    historyList.validateNow();
                             }

                    }

                     

                    when done this way the scrollToIndex() function works without a hitch, still a pain in the arse bug though!