5 Replies Latest reply on Apr 25, 2007 8:43 PM by dennismr

    Scroll events

    dennismr Level 1
      I have some regulatory agreements that customers are required to read before they can register with my company. The agreements are very long and to handle them elegantly I'd like to put them in a text box that the user will have to scroll through to read. I have to prove that they've scrolled to the end of the text box. I see a scroll event that's launched when scrolling begins. Is there any kind of event that will recognize a reader scrolling to the end of the document?
        • 1. Re: Scroll events
          dennismr Level 1
          Does anyone know how I could access the public constant AT_BOTTOM of the ScrollEventDetail class when trying to accomplish this project? Any help would be greatly appreciated.

          Mike
          • 2. Scroll events
            VarioPegged Level 2
            You could use the maxVerticalScrollPosition of the TextArea and compare it to the ScrollEvent position property like so:

            Pardon the gobs of Latin text...

            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

            <mx:Script>
            <![CDATA[

            import mx.events.ScrollEvent;

            // Event handler function to evaluate the scroll position.
            private function myScroll(event:ScrollEvent):void {
            if (event.position == event.currentTarget.maxVerticalScrollPosition) {
            showText.text = "Reached the end!";
            } else {
            showText.text = "Scrolling...";
            }
            }
            ]]>
            </mx:Script>

            <mx:TextArea id="showText" height="100%" width="100%"
            color="blue"
            text=""/>

            <mx:TextArea id="scrollText"
            height="100%" width="100%"
            editable="false"
            color="blue"
            scroll="myScroll(event);"

            text="Sed ut perspiciatis, unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? [33] At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."/>
            </mx:Application>
            • 3. Re: Scroll events
              dennismr Level 1
              Fantastic!! That worked beautifully, thank you very much.

              Can I ask one more question, is there a function that will move the scroll back to the top of the textarea like a click event.
              • 4. Scroll events
                VarioPegged Level 2
                Glad that worked for you...

                Yeah, you can use the setter verticalScrollPosition for the TextArea. Here's a simple function I wrote that you can add to the previous example...

                //This will set the scrollposition back to the top of the TextArea
                private function scrollToTop():void {
                scrollText.verticalScrollPosition = 0;
                showText.text = "Top of the page.";
                }

                Then add the button to control the scrolling back to the top...

                <mx:Button label="Top" id="toTop" click="scrollToTop();" />

                That should do it.
                • 5. Re: Scroll events
                  dennismr Level 1
                  Tremendous! Thanks very much again. You've helped me so much.

                  Mike