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

by Peter deHaan on September 12, 2007

in HSlider, Slider, VSlider

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.

{ 1 comment… read it below or add one }

1 Nice September 15, 2007 at 7:58 pm

AWESOME!

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

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: