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

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.

2 thoughts on “Determining the current scroll position on an FxTextArea control in Flex Gumbo

  1. 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

Comments are closed.