Formatting data tips in a Slider

by Peter deHaan on July 18, 2007

in HSlider, Slider, VSlider

I was playing around with the HSlider the other day and needed to format the data tool tip. Thankfully, the Flex SDK makes it very very easy, all you need to do to override the default data tip using the dataTipFormatFunction property. By simply passing in the name of a user-defined function, you can format the data tip text however you want (such as prefixing dollar signs or what have you).

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/07/18/formatting-data-tips-in-a-slider/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function formatFunction(item:Object):String {
                  return "Minium price: $" + item.toString();
            }
        ]]>
    </mx:Script>

    <mx:HSlider id="slider"
            width="200"
            liveDragging="true"
            minimum="1"
            snapInterval="1"
            tickInterval="1"
            value="3"
            dataTipFormatFunction="formatFunction" />

    <mx:Label id="lbl" text="{slider.value}" />

</mx:Application>

View source is enabled in the following example.

Good luck, and happy Flexing!

{ 3 comments… read them below or add one }

1 Bunche May 18, 2008 at 6:46 pm

Hi. Any tips on how the dataTipFormatFunction can determine which thumb the value refers to when you have more than one thumb? Thanks.

Reply

2 peterd May 19, 2008 at 12:29 am
3 tim December 13, 2009 at 4:32 am

Hi there,

I have a Hslider which i use for my videoplayer. Is it possible for the Datatip to be always visible?

Thanks a bunch!

Tim

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: