Using overlapping slider thumbs in the Flex Slider controls

by Peter deHaan on August 22, 2007

in HSlider, Slider, VSlider

I was playing around with the HSlider component tonight and was checking out the allowThumbOverlap property. The following example creates a horizontal slider with 2 slider thumbs and lets you toggle the allowThumbOverlap property with the showTrackHighlight property set to true.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/22/using-overlapping-slider-thumbs-in-the-flex-slider-controls/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function list_labelFunc(item:Object):String {
                return Number(item).toFixed(2);
            }
        ]]>
    </mx:Script>

    <mx:Number id="slider_thumbCount">2</mx:Number>

    <mx:ApplicationControlBar dock="true">
        <mx:CheckBox id="checkBox"
                label="allowThumbOverlap"
                selected="true" />
    </mx:ApplicationControlBar>

    <mx:HSlider id="slider"
            allowThumbOverlap="{checkBox.selected}"
            dataTipPrecision="2"
            showTrackHighlight="true"
            snapInterval="0.25"
            thumbCount="{slider_thumbCount}"
            tickInterval="1" />

    <mx:List id="list"
            dataProvider="{slider.values}"
            labelFunction="list_labelFunc"
            rowCount="{slider_thumbCount}"
            width="{slider.width}" />

</mx:Application>

View source is enabled in the following example.

{ 6 comments… read them below or add one }

1 Kiruthika April 24, 2008 at 2:45 am

hi,

This is really cool. I am very new to Flex, could you tell what has to be done in order to use this in a program.

Thanks,
Kiruthika

Reply

2 peterd April 24, 2008 at 8:38 am

Kiruthika,

In Flex Builder, create a new Flex Project by selecting File > New > Flex Project from the main menu. Enter a Project name and click “Finish”. Copy and paste the code from above and paste into the MXML file in your Flex project. Finally, select Run > Run <project name> from the main menu to view the Flex application in a web browser.

Peter

Reply

3 Jeff June 3, 2008 at 8:11 am

Hi Peter,

I was wondering if you knew how to position the Thumbs so that they are at each end of the slider? For example on a single thumb slider you could use value=10.

Thanks,
jeff

Reply

4 urva September 14, 2008 at 6:41 pm

Hey Peter,

Impressive! I am new to Flex too and was looking forward to customize my Hslider with two thumbs!

Thanks,
Urva

Reply

5 Niladri August 6, 2009 at 7:36 am

Hi ,I am using a Flex vslider with double thumb.I need a flex code which will change slider body color in such a fashion so that slider portion below lower thumb will show red color,above upper thumb will show green color and portion between two thumb will show orange color.Can u please guide me?

Reply

6 Tejas September 3, 2009 at 12:49 am

If snapInterval is 0.25, why in the allowThumbOverlap, I can’t bring the thumbs to a o.25 interval. They have a 0.5 minimum distance. Would prefer if someone has a solution to this

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: