4 Replies Latest reply on Dec 12, 2009 12:26 AM by E M Storm

    Programmatically dispatching a scroll event

    E M Storm

      Okay, here's the situation:

       

      Initial problem:  I needed to smoothly scroll a TileList, programmatically.  There is no visible scroll bar on the control.

       

      Partial Solution: I found Alex Harui's extended List class that will allow a smoothly scrolling TileList.  If I use a scrollbar to move the TileList, this works just fine.

       

      Remaining problem:  I need this to happen without user input: it needs to scroll on its own.

       

      Question:  How do I dispatch a scroll event to the TileList, so that it thinks that someone clicked the down arrow on the scroll bar?  The TileList already contains the necessary scroll handler, I just need to figure out how to call it based on a timer, rather than based on user input.

       

      Any help?  I've read the Flex reference on the ScrollEvent class, and came away with nothing but a headache. 

       

      Thanks in advance,

      Eric

        • 1. Re: Programmatically dispatching a scroll event
          Flex harUI Adobe Employee

          Do you have a lot of data?  If not, just have the TileList show every tile and put it in a scrolling container.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

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

          • 2. Re: Programmatically dispatching a scroll event
            E M Storm Level 1

            In fact, each tile is merely a number, but there could theoretically be hundreds of them.

             

            The application is for a friend, who occasionally oversees raffle events.  Multiple prizes are awarded, and not every ticket drawn is a winner.  The scrolling display is meant to show whether a participant's number is still "in play", and which numbers have already won something.  Since there could be hundreds of raffle tickets, a scrolling display is a must, and the line-by-line scroll of TileList was very distracting, at least to me.

             

            I have, currently, moved the TileList into a Canvas control, and this does allow smooth scrolling.  However, since adding containers always slows down a program, if there was a way to avoid the extra container, I'd prefer to use it.

             

            Not to mention the knowledge of how to instantiate a ScrollEvent in this way... 

             

            Thanks, anyway

            Eric

            • 3. Re: Programmatically dispatching a scroll event
              Flex harUI Adobe Employee

              If you've turned off the scrollbars, I don't think anybody is listening for events from the scrollbars, so you may have to subclass and call scrollHandler directly.  Maybe something like:

               

                      var event:ScrollEvent = new ScrollEvent(ScrollEvent.SCROLL);

                      event.detail = ScrollEventDetail.LINE_UP; // or ScrollEventDetail.LINE_DOWN

                      event.position = scrollPosition;

                      event.delta = scrollPosition - oldPosition;

                      event.direction = ScrollBarDirection.VERTICAL;

                     scrollHandler(event);

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

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

              • 4. Re: Programmatically dispatching a scroll event
                E M Storm Level 1

                Okay... you've ALMOST answered my question....

                 

                Final piece of the puzzle:   Where do I get scrollPostion and oldPosition from, in your example code?

                 

                Eric