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

by Peter deHaan on December 9, 2008

in FxScroller, FxTextArea, FxVScrollBar, beta

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 comments… read them below or add one }

1 saurabh December 16, 2008 at 5:20 pm

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

Reply

2 Peter deHaan December 16, 2008 at 9:34 pm

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

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: