Styling the data tip on a Spark HSlider control in Flex 4
The following example shows how you can style the data tip on a Spark HSlider control in Flex 4 by creating a custom skin and setting the skinClass style.
Full code after the jump.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/05/18/styling-the-data-tip-on-a-spark-hslider-control-in-flex-gumbo/ --> <s:Application name="Spark_HSlider_skinClass_dataTip_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:HSlider id="slider" skinClass="skins.CustomHSliderSkin" horizontalCenter="0" verticalCenter="0" /> </s:Application>
The custom skin class, skins/CustomHSliderSkin.mxml, is as follows:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/05/18/styling-the-data-tip-on-a-spark-hslider-control-in-flex-gumbo/ --> <s:SparkSkin name="CustomHSliderSkin" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" minHeight="11" alpha.disabled="0.5"> <s:states> <s:State name="normal" /> <s:State name="disabled" /> </s:states> <fx:Metadata> <![CDATA[ [HostComponent("spark.components.HSlider")] ]]> </fx:Metadata> <fx:Script> /* Define the skin elements that should not be colorized. For slider, the skin itself is colorized but the individual parts are not. */ static private const exclusions:Array = ["track", "thumb"]; override public function get colorizeExclusions():Array { return exclusions; } override protected function measure() : void { // Temporarily move the thumb to the left of the Slider so measurement // doesn't factor in its x position. This allows resizing the // HSlider to less than 100px in width. var thumbPos:Number = thumb.getLayoutBoundsX(); thumb.setLayoutBoundsPosition(0, thumb.getLayoutBoundsY()); super.measure(); thumb.setLayoutBoundsPosition(thumbPos, thumb.getLayoutBoundsY()); } </fx:Script> <fx:Declarations> <!--- Defines the appearance of the the Slider's DataTip. To customize the DataTip's appearance, create a custom HSliderSkin class. --> <fx:Component id="dataTip"> <s:DataRenderer minHeight="24" minWidth="40" y="-34"> <s:Rect top="0" left="0" right="0" bottom="0"> <s:fill> <s:SolidColor color="haloBlue" alpha="0.9" /> </s:fill> <s:filters> <s:DropShadowFilter angle="90" color="0x999999" distance="3" /> </s:filters> </s:Rect> <s:Label id="labelDisplay" text="{data}" horizontalCenter="0" verticalCenter="1" left="5" right="5" top="5" bottom="5" textAlign="center" verticalAlign="middle" fontWeight="normal" color="black" fontSize="16" /> </s:DataRenderer> </fx:Component> </fx:Declarations> <!--- Defines the skin class for the HSliderSkin's track. The default skin class is HSliderTrackSkin. --> <s:Button id="track" skinClass="spark.skins.spark.HSliderTrackSkin" left="0" right="0" top="0" bottom="0" minWidth="33" width="100" /> <!--- Defines the skin class for the HSliderSkin's thumb. The default skin class is HSliderThumbSkin. --> <s:Button id="thumb" skinClass="spark.skins.spark.HSliderThumbSkin" top="0" bottom="0" width="11" height="11" /> </s:SparkSkin>
View source is enabled in the following example.
This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.
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.
14 Responses to Styling the data tip on a Spark HSlider control in Flex 4
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


Some changes since SDK 4.0.08945 …
is now gone. Not sure why this was necessary anyway.
Throws an error with ‘data’ now. Not sure how to get this property. Can’t see anything in the latest docs. I’m assuming you need to reference the parent component. Any ideas?
@lee,
Yes. A lot of churn has happened since I wrote this initially. I’ve been trying to go back through all my old Spark-based examples and update them to the latest APIs, but I still have about 150+ Spark/Gumbo examples to test, fix, update, and ideally post SWFs.
Anyways, down to business…
1) Never trust examples on this site will work. ;)
2) Always use the latest Flex 4 SDK possible: http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
3) Always check http://opensource.adobe.com/wiki/display/flexsdk/Rename+List for known API renames. Admittedly, I never really said which build of the SDK this once worked on, but we had a massive API rename around build 4.0.0.7756 (around June 11-18, 2009 — I believe).
Looking at that page it seems that spark.components.MXMLComponent was renamed to spark.components.DataRenderer. Unfortunately, the beta Flex 4 LangRef still shows MXMLComponent as an valid class: http://livedocs.adobe.com/flex/gumbo/langref/spark/components/package-detail.html. (The LangRef was last updated for beta1 [I believe] and was built on Thu May 21 2009, a few weeks before the API renames.)
4) Which brings us to #4. See #2. Always download the latest nightly builds. Around June 24, 2009 we started including Language Reference ZIPs for each nightly build. So if you want to see the latest Language Reference documentation to go with your latest Flex 4 SDK, then download the Lang Ref ZIP and unzip it locally.
Peter
comment got chewed … MXMLComponent class is now gone.
@lee,
Yes. This blog is terrible at eating HTML/MXML/XML tags. You need to escape < as < and > as >
I need to put that big disclaimer back up on the site.
Peter
Hi,
I’ve been trying to skin a slider but I always get the same error: Required skin part track cannot be found.
I’ve been debugging and it seems that de datatip skinpart is not found…
This is the code of the slider’s skinclass:
Any idea how to fix it ?
Updated example to Flex SDK 4.0.0.10008 (s:SimpleText is now s:Label).
Peter
This seems to work thanks for your help. I love this blog it’s full of great Flaex 4.0 stuff.
is it possible to always show de dataTip?
Can/did anyone answer the question “is it possible to always show the dataTip?” I would also like a solution for this.
Thanks!
Tony
how can i increase thickness of this Hslider. I want to increase height of that line in which thumb moves left to right…
@piyush,
See “Skinning the track on a Spark HSlider control in Flex 4″.
Peter
Tony…
please refer http://blog.flexexamples.com/2007/09/11/customing-the-flex-hslider-and-vslider-controls/
hope u ll find your answer in this site…
Is there a way to style the datatip with CSS?