In Flex, if you have a custom slider thumb, it will always be scaled to a set size that Flex wants (I think 20×20).

For example,

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        backgroundColor="#ffffff"
        width="300" height="100">
    <mx:HSlider thumbSkin="@Embed(source='resources/images/mario8bit.png')" />
</mx:Application>

would give you this:

The Flash plugin is required to view this object.

To fix this, I wrote a class that extends SliderThumb and sets to the measured size of the skin image:

package controls.sliderClasses {
    import mx.controls.sliderClasses.SliderThumb;
    import mx.core.mx_internal;
   
    use namespace mx_internal;
   
    public class FlexibleSliderThumb extends SliderThumb {
       
        override protected function measure():void {
            super.measure();
            measuredWidth = currentSkin.measuredWidth;
            measuredHeight = currentSkin.measuredHeight;
        }
    }
}

Now, modifying the mxml file like so:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        backgroundColor="#ffffff"
        width="300" height="100">
    <mx:Script>
        <![CDATA[
            import controls.sliderClasses.FlexibleSliderThumb;
        ]]>
    </mx:Script>
    <mx:HSlider
        thumbSkin="@Embed(source='resources/images/mario8bit.png')"
        sliderThumbClass="{controls.sliderClasses.FlexibleSliderThumb}"/>
</mx:Application>

gives you this:

The Flash plugin is required to view this object.

2 Responses to “Custom width and height of Flex Slider thumb”

  1. on 16 Jul 2008 at 6:04 pm monkey said …

    You should provide code for a sample app and maybe a failure app which shows the problem you’re trying to fix.

  2. on 13 Aug 2008 at 7:19 pm Frank Lam said …

    done

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply