Flex Examples
Customing the Flex HSlider and VSlider controls
The following example shows how you can customize several properties and styles in the Flex HSlider control.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2007/09/11/customing-the-flex-hslider-and-vslider-controls/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" verticalAlign="middle" backgroundColor="white" creationComplete="init();"> <mx:Style> .MyDataTip { backgroundAlpha: 1.0; backgroundColor: haloBlue; color: white; fontWeight: bold; } </mx:Style> <mx:Script> <![CDATA[ private function init():void { slider.labels = [slider.minimum, slider.maximum]; } ]]> </mx:Script> <mx:ApplicationControlBar dock="true"> <mx:Form> <mx:FormItem label="allowTrackClick:"> <mx:CheckBox id="allowTrackClickCh" selected="true" /> </mx:FormItem> <mx:FormItem label="invertThumbDirection:"> <mx:CheckBox id="invertThumbDirectionCh" /> </mx:FormItem> <mx:FormItem label="showTrackHighlight:"> <mx:CheckBox id="showTrackHighlightCh" selected="true" /> </mx:FormItem> <mx:FormItem label="showDataTip:"> <mx:CheckBox id="showDataTipCh" selected="true" /> </mx:FormItem> <mx:FormItem label="dataTipPlacement:"> <mx:ComboBox id="dataTipPlacementCB" selectedIndex="2"> <mx:dataProvider> <mx:Array> <mx:Object label="left" /> <mx:Object label="right" /> <mx:Object label="top" /> <mx:Object label="bottom" /> </mx:Array> </mx:dataProvider> </mx:ComboBox> </mx:FormItem> <mx:FormItem label="dataTipPrecision:"> <mx:NumericStepper id="dataTipPrecisionNS" minimum="0" maximum="3" value="2" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:HSlider id="slider" invertThumbDirection="{invertThumbDirectionCh.selected}" minimum="-10" maximum="20" tickInterval="5" liveDragging="true" showDataTip="{showDataTipCh.selected}" showTrackHighlight="{showTrackHighlightCh.selected}" dataTipPlacement="{dataTipPlacementCB.selectedItem.label}" allowTrackClick="{allowTrackClickCh.selected}" dataTipPrecision="{dataTipPrecisionNS.value}" dataTipStyleName="MyDataTip" /> </mx:Application>
View source is enabled in the following example.
Tagged with: allowTrackClick • dataTipPlacement • dataTipPrecision • dataTipStyleName • showDataTip • showTrackHighlight
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.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
29 Responses to Customing the Flex HSlider and VSlider controls
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Can we change the track height for the HSlider?
Aasim,
I don’t believe there is a style/property specifically for track height. You can probably just create a custom skin though. If you think it is a bug, or want to file an enhancement request, you can go to http://bugs.adobe.com/flex/ and submit it to the official Flex bug base.
Peter
Thanks Peter,
just another question…
a hslider track bar has a small offset of around 3 pixels from the left and the right side, can this be reduced?
Aasim,
Not sure. I believe the Slider class (mx.controls.sliderClasses.Slider) has a “thumbOffset” style which may be what you are looking for. If not, you may have to try asking on Flexcoders and see if somebody on there knows.
Sorry,
Peter
Is there a way to change the order of the min max positions on the slider so that the max value is on the left and the min value on the right?
Pedro,
There isn’t a way I know of, although you could probably extend the Slider (or HSlider/VSlider) class and add the functionality. Either that or just use the labelFunction and handle all the value conversions behind the scenes manually. You could always try asking on the Flexcoders list, I’m sure somebody out there has attempted this before.
Sorry,
Peter
Note: These questions always work better if I already know the answers. Otherwise I just look kind of silly. ;)
Hi Peter
Please help me in achieving the following:
“To drag the region between the thumbs, if the HSlider has two thumbs”.
Do we have any option in HSlider?
Or
Do i need to rewrite HSlider which will implement Slider?
Thanx in advance
~Anand
Anand,
Something like Doug McCune’s “Draggable Slider Component for Flex“?
Peter
I know there is a way to set the toolTip for the slider, but do you know of a way to override the dataTip to display something else?
I’m using the DisplayShelf component to display images, and as the slider moves, I want to update the dataTip with the name or caption of the image.
Any ideas?
Erich,
Do either of the following entries help?
http://blog.flexexamples.com/2007/07/18/formatting-data-tips-in-a-slider/
http://blog.flexexamples.com/2007/07/23/formatting-multiple-data-tips-in-a-slider/
Peter
Peter,
The first link had exactly what I needed – thank you!!!
-Erich-
Hi,..
Is it possible to rotate the silder label text??
I tried with applying styles like
HSlider { label-rotation:90; }and
HSlider { label-style-name:mySliderStyle; } .mySliderStyle { rotation:90; }But both of them didnt work
Last question is similar to a problem I’m having – can I display the VSlider track on the left of the labels? Why is there no labelPlacement property for the sliders? I think it’s a rather simple and important feature. Any way around it?
Greg K.,
Can you file a bug/enhancement request at http://bugs.adobe.com/flex/ and post the bug number here so a few of us can vote on the issue?
It seems like it would be a common use case, and possibly something that can be addressed in the Flex Gumbo components.
Peter
@Greg:
You can set the labeloffset to accomplish this:
Maybe not pretty, but it works…
Dear Peter,
is it possible to create a custom changeSlider event and get the HSlider’s thumb data via a Method which I can’t find?
Afterwards I would like to use that data to display it via labels or to do some sort of calculations with it.
Regards,
Ian
Ian,
You can listen for the
changeevent to detect when the selected value has changed and then get the current thumb value.Peter
Thanks a lot Peter,
if I understand you correctly, then I should use the SliderEvent and its CHANGE constant, f.ex.
private function sliderChangeOne():void { var StandardEvent:SliderEvent=new SliderEvent(SliderEvent.CHANGE); dates.text=StandardEvent.value.toString(); dispatchEvent(StandardEvent);in order to get a sliderThumb value such as a certain month into my textbox “dates”.
Jan
Ian/Jan,
If you only want to get the current value of the HSlider/VSlider, you can just use the “value” property to get the current slider control’s value:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Label id="lbl1" /> <mx:HSlider id="sldr1" minimum="0" maximum="11" snapInterval="1" liveDragging="true" change="lbl1.text = sldr1.value.toString();" /> </mx:Application>Or, you can use data binding:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Label id="lbl1" text="{sldr1.value}" /> <mx:HSlider id="sldr1" minimum="0" maximum="11" snapInterval="1" liveDragging="true" /> </mx:Application>Or, if you want to do it all using ActionScript:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init();"> <mx:Script> <![CDATA[ import mx.controls.HSlider; import mx.controls.Label; import mx.events.SliderEvent; private var lbl1:Label; private var sldr1:HSlider; private function init():void { lbl1 = new Label(); addChild(lbl1); sldr1 = new HSlider(); sldr1.minimum = 0; sldr1.maximum = 11; sldr1.snapInterval = 1; sldr1.liveDragging = true; sldr1.addEventListener(SliderEvent.CHANGE, sldr1_change); addChild(sldr1); } private function sldr1_change(evt:SliderEvent):void { lbl1.text = sldr1.value.toString(); } ]]> </mx:Script> </mx:Application>Peter
Shameer Salim,
I don’t think that label rotation is supported by the components. You’d probably need to extend the HSlider/VSlider control(s) and add that logic in (and make sure you always used an embedded font since device font cannot be rotated).
Feel free to file an enhancement request for label rotation at http://bugs.adobe.com/flex/
Peter
Hello there,
I just can’t find any information about changing the color of the Slider labels.
Do I have to do this by using Styles?
I need white labels on my black background…
kind regards,
Julia
Oh, sorry .. I went to found the solution…
.myLabelStyle { color: white; }Could u please explain how to highlight the lable based on the Hslider value.
Is there a way to make the track highlight on the right side (thumb value to max value) instead of the left (min value to thumb value)?
Thanks
If you set ‘dataTipPlacement’ to ‘left’ or ‘right’ in this example, a small horizontal line is visible under the tooltip. Is this a (known) bug? I actually have the same feature in one of my applications, but then when ‘dataTipPlacement’ is set to ‘top’ as well.
Does anybody know how to get rid of this line?
Thanks,
Eugene
is it possible to create Date Time HSlider & how?
Best Regards,
Monali
@Monali,
Sure, something like this will let you use an HSlider control to select a date:
Peter
Thanks, this is what I’ve looked for. Alternatively, you may use “data-tip-style-name” in the slider’s CSS definition to define the style for the tip.
Peter, can we change the button in here with our own swf or png?