3 Replies Latest reply on Jul 14, 2010 12:38 AM by SVenu_2703

    Help me on HSlider with two thumbs

    SVenu_2703 Level 1

      Hi Friends,

      I have a problem with HSlider. I am working on a slider with two thumbs. I have a requirement to overlap two thumbs. But the problem with overlapping is i can slide in reverse also. I need to restrict that. Please suggest me solution and save my time.

      I will explain with example:
      I have a slider to select classes from 1 - 12. For this i am using HSlider with two thumbs.
      Now a user can select class range between 1 - 12. i.e., 5-6 or 8-9 or 2-9 etc..
      I am giving an option to select 1-1 or 4-4 or 5-5 by overlapping the thumbs.

      Now the problem i am facing is : user can select 9-5 or 6-1 or 5-3 etc, because i am giving chance to overlap thumbs.
      But i have to restrict that behaviour... The user should not be able to select reverse.

      I tried to Override getSnapValue method to restirct that behavior. But it is not working as expected. Please suggest me a solution for this. Please share me if you have any example which is having same or similar behavior.

       

       

      Thanks,

      Venu S.

        • 1. Re: Help me on HSlider with two thumbs
          BhaskerChari Level 4

          Hi Venu,

           

          Can you post the code that you are working reproducing your problem..?

          Normally HSlider won't allow its thumbs to be dragged reverse of another one...

           

           

          Thanks ,

          Bhasker Chari

          • 2. Re: Help me on HSlider with two thumbs
            SVenu_2703 Level 1

            Hi Bhasker,

            Thanks for immediate response.

             

            Here is my code:

             

            package

             

            {

             

             

            import mx.controls.HSlider;

             

            import mx.controls.sliderClasses.SliderThumb;

             

            import mx.core.mx_internal;

             

             

            use namespace mx_internal;

             

             

            public class CustonSlider extends HSlider

            {

             

            public function CustonSlider ()

            {

            }

             

             

            override mx_internal function getSnapValue(value:Number, thumb:SliderThumb = null):Number

            {

             

            if (!isNaN(snapInterval) && snapInterval != 0)

            {

             

            var val:Number = getValueFromX(value);

             

             

            trace("value min max val "+value+" "+minimum+" "+maximum+" "+val);

             

            //if (thumb && (thumbs.numChildren > 1) && !allowThumbOverlap)

             

             

            if (thumb && (2 > 1) && !allowThumbOverlap)

            {

             

            var check_bounds:Boolean = true;

             

            var bounds:Object

             

            bounds = getXBounds(thumb.thumbIndex);

             

             

            var prevThumb:SliderThumb =

            thumb.thumbIndex > 0 ?

             

            //SliderThumb(thumbs.getChildAt(thumb.thumbIndex- 1)) :

            SliderThumb(getThumbAt(thumb.thumbIndex- 1)) :

             

             

            null;

             

             

            var nextThumb:SliderThumb =

             

            //thumb.thumbIndex + 1 < thumbs.numChildren ?

            thumb.thumbIndex + 1 < 2 ?

             

             

            //SliderThumb(thumbs.getChildAt(thumb.thumbIndex + 1)) :

            SliderThumb(getThumbAt(thumb.thumbIndex + 1)) :

             

             

            null;

             

             

            if (prevThumb)

            {

            bounds.min -= (prevThumb.width / 2);

             

            trace("bounds.min "+bounds.min);

             

            // check if thumb is at minimum, if not we can ignore the bounds logic

             

             

            if (val == minimum)

             

            if (getValueFromX((prevThumb.xPosition - prevThumb.width/2)) <= minimum)

            check_bounds =

            false;

            }

             

            else

            {

             

             

            if (val >= minimum)

            check_bounds =

            false;

            }

             

             

            if (nextThumb)

            {

            bounds.max += (nextThumb.width / 2);

             

            trace("bounds.max "+bounds.max);

             

            // check if thumb is at maximum, if not we can ignore the bounds logic

             

             

            if (val == maximum)

             

            if (getValueFromX((nextThumb.xPosition + nextThumb.width/2)) >= maximum)

            check_bounds =

            false;

            }

             

            else

            {

             

             

            if (val <= maximum)

            check_bounds =

            false;

            }

             

            trace("check_bounds : "+check_bounds);

             

            if (check_bounds)

            val = Math.min(Math.max(val, getValueFromX(Math.round(bounds.min)) + snapInterval),

            getValueFromX(Math.round(bounds.max)) - snapInterval);

             

            }

             

             

            return getXFromValue(val);

            }

             

             

            return value;

            }

             

             

            }

            }

             

             

            I am calling the above snippet in my application.

            But it is not working as i expected. Let us consider two thumbs as left thumb and right thumb, the left thumb should not move to right and rite thumb should move to right thumb. I can achieve this functionality if i set the boolean property "allowThumbOverlap" to false. But if i did this i cannot select range between 1-1 0r 4-4 or 9-9 etc. I have to give a chance to select range between 1-1 or  4-4 or 9-9 etc

             

            Message was edited by: SVenu_2703

            • 3. Re: Help me on HSlider with two thumbs
              SVenu_2703 Level 1

              Friends,

              Can i have a solutions for this. I need it very urgent.

               

              Thanks,

              Venu S.