4 Replies Latest reply on Jul 23, 2010 6:33 AM by ozDiGennaro

    How do I build a Scroller in Actionscript?

    ozDiGennaro Level 1

      I need to build a Scroller / Group / RichEditableText set of components using only Actionscript, since I need to create (perhaps) many of these, skinned on-the-fly as a result of download from the server.


      Can anyone provide a working example?  I can see how to do it using MXML, but I'm a programmer at heart...  Only actionscript?  I've tried but I'm having trouble getting the pieces to play together (scroll bars, mouse wheel, etc.)


      Or is there a way to create multiple instances of a set of components defined in MXML?  That might do it too.




        • 1. Re: How do I build a Scroller in Actionscript?
          rootsounds Level 4

          I'm not clear on what you are trying to accomplish. Could you perhaps provide an illustration?

          • 2. Re: How do I build a Scroller in Actionscript?
            ozDiGennaro Level 1

            I have a very dynamic application:  the windows and components come and go, and I don't know in advance how many there will be, what the styles will be, etc.

            So I want to create all components with Actionscript classes.

            This is the MXML code that creates what I want.. This works fine, scrolls, mouse-wheel, all controls are effective.


            <s:Scroller id="myScrollerA" width="300" height="100">
                <s:Group id="myGroupA">
                    <s:RichEditableText id="myTextA" paddingTop="20">
                                <s:p fontWeight="bold">This is paragraph 1.</s:p>
                                <s:p>This is paragraph 2.</s:p>
                                <s:p>This is paragraph another.</s:p>
                                ... more code here with more text


            This is the Actionscript I'm starting with, but the linking between the vertical scroll bar and the text scrolling is not functioning, and there are various surprises.


                          sxText is an instance of my custom class which subclasses RichEditableText, with more text than will fit into the scroller.


                        group = new Group();
                        scroller = new Scroller();
                        scroller.viewport = group;


            The scroll bar does scroll the content area, but NOT the text -- the text disappears off the top, but the revealed area at the bottom is background color: no text content.

            Mouse wheel on the text area functions, but the scrolling is not reflected in the scroll bar.

            Also puzzling:  the thumb component of the scroll bar changes to a large vertical size, on first click into any scroll bar component.


            What else do I need to do to tightly couple the scrolling of the text area and the use of the vertical scroll bar?  Am I missing some skinning methods?


            Thanks for your attention.

            • 3. Re: How do I build a Scroller in Actionscript?
              jsd99 Level 3

              You could just create an MXML component which has the XML structure you pasted above, and use ActionScript to dynamically set the properties of it at runtime.  MXML components can be instantiated just like any ActionScript class.

              • 4. Re: How do I build a Scroller in Actionscript?
                ozDiGennaro Level 1

                Thanks.  I followed that path. and it works.  Still some mysteries, but I'll live with them.

                I'll post some sample code soon.