Customizing the slide duration and slide easing function on a Flex slider control

The following example shows how you can customize the duration and easing function used when a user clicks on a thumb track on an HSlider or VSlider control in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/12/customizing-the-slide-duration-and-slide-easing-function-on-a-flex-slider-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import mx.events.NumericStepperEvent;
            import mx.effects.easing.*;

            private var arr:Array;

            private function init():void {
                arr = new Array();
                arr.push({label:"Elastic.easeInOut", func:Elastic.easeInOut});
                arr.push({label:"Bounce.easeOut", func:Bounce.easeOut});
                arr.push({label:"Back.easeIn", func:Back.easeIn});

                easingFunc.dataProvider = arr;
            }

            private function duration_change(evt:NumericStepperEvent):void {
                slider.setStyle("slideDuration", evt.value);
            }

            private function easingFunc_change(evt:ListEvent):void {
                slider.setStyle("slideEasingFunction", easingFunc.selectedItem.func);
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Label text="slideDuration:" />
        <mx:NumericStepper id="duration"
                minimum="0"
                maximum="2000"
                value="300"
                stepSize="100"
                change="duration_change(event);" />

        <mx:Label text="slideEasingFunction:" />
        <mx:ComboBox id="easingFunc"
                change="easingFunc_change(event);"
                prompt="Please select an easing function..." />
    </mx:ApplicationControlBar>

    <mx:HSlider id="slider" showTrackHighlight="true" tickInterval="1" />

</mx:Application>

View source is enabled in the following example.

0 thoughts on “Customizing the slide duration and slide easing function on a Flex slider control