Ruler Spark Component using dynamic skin parts and custom GraphicElement
Keywords: component, FXG, GraphicElement, skin parts, Spark
Here’s a first version of a simple Ruler component that takes some of the techniques discussed in the couple of previous post into account.
The ruler can be scaled down or up by holding CTRL/SHIFT while clicking and can be moved by holding the ALT-Key and keeping the mouse button pressed. When scaling an animation is applied for smoother transitions. For the labels an array of Strings can be set, each one defining a division on the ruler. The number of subdivisions can be set as well
Simple ruler component. View source is enabled.
Custom GraphicElement to draw tick lines
Instead of using and FXG-Path element a custom GraphicElement has been created to draw the tick lines. This makes for a cleaner and more generic approach when drawing the ruler and reduces overhead when animation is applied while scaling.
Dynamic skin parts for the Labels
For the labels dynamic skin parts are used. Here’s a little recap on how to work with dynamic skin parts.
- Declare a dynamic skin part in the Declarations segment of the skin. Wrap it up in a Component and give the component an id.
- Declare the skin part in the component, referencing it via id in the skin. The type is of mx.core.IFactory.
- To create a dynamic skin part at runtime call createDynamicPartInstance([id of skin part]) from the component. This will return an instance of the desired skin part.
- In the component add this instance to the skin or a group within the skin.
- Optionally add it to an array for dynamically created instances for easier housekeeping.
- Any Listener is best added in partAdded() similar to adding behavior to static skin parts. When adding event listeners do not forget to remove them in partRemoved().
- A dynamic skin part can be removed at runtime by calling removeDynamicPartInstance([id of skin part], instance). You also need to manually remove the instance form the group you’ve added them.
If you need more information on dynamic skin parts, check out this great article by Florian Fesseler.
Similar Posts
Custom PopUp Rating Component in Spark Flex 4 (Gumbo)
Inspecting and creating a custom Spark GraphicElement
Skinning and creating custom rating component in flex 4 (Gumbo)
Advanced FXG Spark Icon Buttons with one generic skin in Flex4 (Gumbo)
Customize the Spark TextInput Component in Flex 4 (Gumbo). Adding focus and Transitions.


October 8th, 2010 at 12:09 pm
wowo very cool, thx 4 the source
October 8th, 2010 at 11:53 pm
Very cool! nice to see a great example what you can do with dynamic skin parts.
On my project i use already the nice tooltips in combination with a dependency injection framework. I love your examples and what you do with flex 4.
Regards from germany
Gurkerl