Removing the thumb button on a Spark VScrollBar control in Flex 4

In a previous example, “Removing the increment and decrement buttons on a Spark VScrollBar control in Flex 4”, we saw how you could remove the increment and decrement buttons on a Flex 4 Spark VScrollBar control by creating a custom skin and setting the skinClass style.

The following example shows how you can remove the thumb button on a Flex 4 Spark VScrollBar control 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 www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see 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.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/02/26/removing-the-thumb-button-on-a-fxvscrollbar-control-in-flex-gumbo/ -->
<s:Application name="Spark_VScrollBar_skinClass_thumb_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">
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/halo";
 
        s|TextArea s|VScrollBar {
            skinClass: ClassReference("skins.CustomVScrollBarSkin");
        }
    </fx:Style>
 
    <fx:Script>
        <![CDATA[
            import spark.utils.TextFlowUtil;
        ]]>
    </fx:Script>
 
    <fx:Declarations>
        <fx:String id="lorem" source="lorem.html" />
    </fx:Declarations>
 
    <s:VGroup horizontalCenter="0" verticalCenter="0">
        <s:TextArea id="textArea"
                textFlow="{TextFlowUtil.importFromString(lorem)}"
                verticalScrollPolicy="on"
                editable="false" />
 
        <s:VScrollBar id="vsb"
                minimum="0"
                maximum="1000" />
    </s:VGroup>
 
</s:Application>

And the custom Spark VScrollBar skin, CustomVScrollBarSkin.mxml, is as follows:

View CustomVScrollBarSkin.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/02/26/removing-the-thumb-button-on-a-fxvscrollbar-control-in-flex-gumbo/ -->
<s:SparkSkin name="CustomVScrollBarSkin"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        minWidth="15" minHeight="35"
        alpha.disabled="0.5">
    <s:states>
        <s:State name="normal" />
        <s:State name="disabled" />
    </s:states>
 
    <fx:Metadata>
        <![CDATA[ 
        [HostComponent("spark.components.VScrollBar")]
        ]]>
    </fx:Metadata> 
 
    <fx:Script>
        /* Define the skin elements that should not be colorized. 
        For scroll bar, the skin itself is colorized but the individual parts are not. */
        static private const exclusions:Array = ["track", "decrementButton", "incrementButton"];
 
        override public function get colorizeExclusions():Array {return exclusions;}
    </fx:Script>
 
    <!--- Defines the skin class for the VScrollBarSkin's track. The default skin class is VScrollBarTrackSkin. -->
    <s:Button id="track" top="16" bottom="15" height="54"
              focusEnabled="false"
              skinClass="spark.skins.spark.VScrollBarTrackSkin" />
 
    <!--- Defines the skin class for the up button of the VScrollBarSkin. The default skin class is ScrollBarUpButtonSkin. -->
    <s:Button id="decrementButton" top="0"
              focusEnabled="false"
              skinClass="spark.skins.spark.ScrollBarUpButtonSkin" />
 
    <!--- Defines the skin class for the down button of the VScrollBarSkin. The default skin class is ScrollBarDownButtonSkin. -->
    <s:Button id="incrementButton" bottom="0"
              focusEnabled="false"
              skinClass="spark.skins.spark.ScrollBarDownButtonSkin" />
 
</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.

2 thoughts on “Removing the thumb button on a Spark VScrollBar control in Flex 4

  1. Clicking on the track throws an error. Can not access a property etc. It’s trying to find the thumb to update its position.

Comments are closed.