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

0 Responses to Setting the tick length on a Slider control in Flex

  1. stoimen says:

    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.

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