Displaying scroll tips in a List control in Flex

by Peter deHaan on March 28, 2008

The following example shows how you can display scroll tips in a Flex List control by setting the showScrollTips property. You can also customize the scroll tip text by setting a custom scroll tip function using the scrollTipFunction property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/28/displaying-scroll-tips-in-a-list-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.scrollClasses.ScrollBarDirection;
            import mx.utils.StringUtil;

            private function list_scrollTipFunc(dir:String, pos:Number):String {
                var pct:Number = pos / list.maxVerticalScrollPosition;
                return StringUtil.substitute("{0} / {1} ({2}%)",
                        pos, // current
                        list.maxVerticalScrollPosition, // max
                        numberFormatter.format(pct * 100) // percent
                    );
            }
        ]]>
    </mx:Script>

    <mx:NumberFormatter id="numberFormatter" precision="0" />

    <mx:Array id="arr">
        <mx:Object label="Accordion" />
        <mx:Object label="ApplicationControlBar" />
        <mx:Object label="Box" />
        <mx:Object label="Canvas" />
        <mx:Object label="ControlBar" />
        <mx:Object label="DividedBox" />
        <mx:Object label="Form" />
        <mx:Object label="FormHeading" />
        <mx:Object label="FormItem" />
        <mx:Object label="Grid" />
        <mx:Object label="HBox" />
        <mx:Object label="HDividedBox" />
        <mx:Object label="Panel" />
        <mx:Object label="TabNavigator" />
        <mx:Object label="Tile" />
        <mx:Object label="TitleWindow" />
        <mx:Object label="VBox" />
        <mx:Object label="VDividedBox" />
        <mx:Object label="ViewStack" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="showScrollTips:"
                labelPlacement="left"
                selected="true" />
    </mx:ApplicationControlBar>

    <mx:List id="list"
            dataProvider="{arr}"
            rowCount="6"
            showScrollTips="{checkBox.selected}"
            scrollTipFunction="list_scrollTipFunc"
            verticalScrollPolicy="on" />

</mx:Application>

View source is enabled in the following example.

{ 4 comments… read them below or add one }

Rafael April 4, 2008 at 3:45 pm

I don’t think this sample is working, I don’t see the scrolltip being displayed regardless of the checkbox status.

Reply

peterd April 4, 2008 at 3:53 pm

Rafael,

I see the scroll tip in the example above (using WinXP/FP9,0,115,0/IE7). It’s a little hard to see since it is actually over the List control itself.

Peter

Reply

Arulmurugan April 9, 2008 at 10:25 pm

Hi Peter

I am using a multiselect listbox how will I access the values in another page (ASP) selected when the page is submitted.

Based on the selection I need to select some records from database.

If you need the source code I will send it to you

Regards,
Arulmurugan . T
Web Developer

Reply

Dewey June 2, 2008 at 8:31 am

I think the confusion on the tooltip not showing isn’t that it isn’t showing (it is), but the expectations. I was initially expecting to see content tooltips as I moused over ‘TabNavigator’, ‘Tile’, etc. What this is doing is adding Tooltips to the scroll bar — which is exactly what it says it is doing… lol

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

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: