The following example shows how you can display scroll tips in a Flex HorizontalList control by setting the Boolean showScrollTips property.

Full code after the jump.

View MXML

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

    <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:HorizontalList id="horizontalList"
            dataProvider="{arr}"
            columnWidth="175"
            columnCount="3"
            rowCount="1"
            rowHeight="100"
            showScrollTips="true" />

</mx:Application>

View source is enabled in the following example.

If you want to customize the scroll tip’s appearance, you can set the ToolTip style in an external .CSS file or <mx:Style /> block, as shown in the following snippet:

<mx:Style>
    ToolTip {
        backgroundColor: haloBlue;
        color: white;
        fontWeight: bold;
    }
</mx:Style>

If you want to customize the scroll tip’s text, you can set the scrollTips property to true and set the scrollTipFunction property, as shown in the following example:

View MXML

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

    <mx:Style>
        ToolTip {
            backgroundColor: haloBlue;
            color: white;
            fontWeight: bold;
        }
    </mx:Style>

    <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:Script>
        <![CDATA[
            import mx.controls.listClasses.TileBaseDirection;

            private function horizontalList_scrollTipFunc(direction:String, position:Number):String {
                var str:String;
                var max:Number;
                var pct:String;

                switch (direction) {
                    case TileBaseDirection.HORIZONTAL:
                        max = horizontalList.maxHorizontalScrollPosition;
                        break;
                    case TileBaseDirection.VERTICAL:
                        max = horizontalList.maxVerticalScrollPosition;
                        break;
                }

                pct = numberFormatter.format(position / max * 100);
                str = position + " of " + max + " (" + pct + "%)";

                return str;
            }
        ]]>
    </mx:Script>

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

    <mx:HorizontalList id="horizontalList"
            dataProvider="{arr}"
            columnWidth="175"
            columnCount="3"
            rowCount="1"
            rowHeight="100"
            showScrollTips="true"
            scrollTipFunction="horizontalList_scrollTipFunc" />

</mx: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.

One Response to Displaying scroll tips in a HorizontalList control in Flex

  1. carlos says:

    Awesome dude it’s just fine.

    i do have a Q. , how to set a label with a color, for example “acordion=red” or “box=blue” . Thanks.

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