The following example shows how you can get a Flex Gumbo FxTextArea control’s current vertical scroll position and maximum scroll position by accessing the FxTextArea control’s internal FxScroller instance’s vertical scroll bar.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3″.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/12/09/determining-the-current-scroll-position-on-an-fxtextarea-control-in-flex-gumbo/ -->
<Application name="FxTextArea_scroller_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Script>
        <![CDATA[
            import mx.components.FxVScrollBar;

            private function init():void {
                var vsb:FxVScrollBar = textArea.scroller.verticalScrollBar;
                var min:Number = vsb.minimum;
                var val:Number = vsb.value;
                var max:Number = vsb.maximum;
                lbl1.text = min.toString();
                lbl2.text = val.toString();
                lbl3.text = max.toString();
                progressBar.setProgress(val, max);
            }
        ]]>
    </Script>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="minimum:">
                <Label id="lbl1" />
            </FormItem>
            <FormItem label="value:">
                <Label id="lbl2" />
            </FormItem>
            <FormItem label="maximum:">
                <Label id="lbl3" />
            </FormItem>
            <FormItem>
                <ProgressBar id="progressBar"
                        mode="manual"
                        label="%1 / %2 (%3%%)" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <FxTextArea id="textArea"
            width="100%"
            height="100%"
            enterFrame="init();">
        <content>
            <String source="data/lorem.html" />
        </content>
    </FxTextArea>

</Application>

View source is enabled in the following example.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

2 Responses to Determining the current scroll position on an FxTextArea control in Flex Gumbo

  1. saurabh says:

    I cant find the data directory containing the lorem.html. any pointers?

  2. Peter deHaan says:

    saurabh,

    The contents of the file don’t matter, you can simply create a lorem.html file in a data subdirectory and paste enough text so the FxTextArea control scrolls.

    Peter

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree