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.

 
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 Customizing the slide duration and slide easing function on a Flex slider control

  1. Nice says:

    AWESOME!

    peterd, how can you make that much cool stuffs on this site? -_–

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