2 Replies Latest reply on Apr 2, 2008 4:33 PM by Peter deHaan

    Slider label formatting?

    Handycam Level 1
      I have a slider meant to show years from 1400 to 2010:
      <mx:HSlider minimum="1400" maximum="2010" width="500" dataTipFormatFunction="showYear" change="yearSliderHandler(event)" liveDragging="true" id="hslider1"/>

      I want the slider tooltip to show the years as I drag. With no formatter it shows numbers like 1,400.25, so I use this formatter function:
      private function showYear(val:String):String {
      return ("Year: "+(Math.round(Number(val)/100)*100));
      }

      However, now it only shows centuries: 1400,1500,1600 etc as I drag the thumb. What am I missing here?
        • 1. Re: Slider label formatting?
          dragonmagik
          you can set the snap interval of your slider so that it only accepts whole numbers ... as in
          <mx:HSlider minimum="1400" maximum="2010" width="500" dataTipFormatFunction="showYear" change="yearSliderHandler(event)" liveDragging="true" id="hslider1" snapInterval="1"/>

          that way your slider will 'snap' to whole numbers.
          • 2. Re: Slider label formatting?
            Peter deHaan Level 4
            Handycam,

            In addition to the snapInterval, you may want to use your dataTipFormatFunction to just return the unformatted value, so you dont get years like "1,944.00":

            <mx:HSlider minimum="1400" maximum="2010" width="500" dataTipFormatFunction="showYear" snapInterval="1" liveDragging="true" id="hslider1"/>

            <mx:Script>
            <![CDATA[
            private function showYear(val:Number):String {
            return val.toString();
            }
            ]]>
            </mx:Script>

            Peter