Setting the tick length on a Slider control in Flex

by Peter deHaan on June 4, 2008

in HSlider, Slider, VSlider

In a previous example, “Setting the tick thickness on a Slider control in Flex”, we saw how to change the thickness of a tick on a Flex HSlider control by setting the tickThickness style.

The following example shows how you can set the length of a tick on a Flex HSlider control by setting the tickLength style.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/04/setting-the-tick-length-on-a-slider-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:HSlider id="slider"
            minimum="0"
            maximum="10"
            value="3"
            liveDragging="true"
            tickLength="{slider.value}"
            tickInterval="1" />

</mx:Application>

View source is enabled in the following example.

You can also set the tickLength style in an external .CSS file or <mx:Style /> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/04/setting-the-tick-length-on-a-slider-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        HSlider {
            tickLength: 10;
        }
    </mx:Style>

    <mx:HSlider id="slider"
            minimum="0"
            maximum="10"
            value="3"
            liveDragging="true"
            tickInterval="1" />

</mx:Application>

Or, you can also set the tickLength style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/06/04/setting-the-tick-length-on-a-slider-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.events.SliderEvent;

            private function slider_change(evt:SliderEvent):void {
                slider.setStyle("tickLength", evt.value);
            }
        ]]>
    </mx:Script>

    <mx:HSlider id="slider"
            minimum="0"
            maximum="10"
            value="3"
            liveDragging="true"
            tickInterval="1"
            change="slider_change(event);" />

</mx:Application>

{ 1 comment… read it below or add one }

1 stoimen March 19, 2009 at 12:03 am

Hi, I was wondering if there is a component with variable length of tick marks. No they are all with the same length, and I’m looking for something like a chart / scale? Is it possible to make such a component?

You do great job. Good luck.

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: