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

by Peter deHaan on February 26, 2009

in TextArea (Spark), VScrollBar (Spark), beta1

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 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".

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.

{ 1 comment… read it below or add one }

1 Peter deHaan July 16, 2009 at 7:30 am

Updated example to work with Flex 4.0.0.8469+ SDK.

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: