The following example shows how you can remove the track skin from a Flex List control by setting the trackSkin style to null.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/04/10/removing-the-track-skin-from-a-list-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Style>
        .tracklessScrollBar {
            trackSkin: ClassReference(null);
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            import mx.events.ItemClickEvent;

            private function toggleButtonBar_itemClick(evt:ItemClickEvent):void {
                list.setStyle("verticalScrollBarStyleName", evt.item.data);
            }
        ]]>
    </mx:Script>

    <mx:Array id="arr">
        <mx:Object label="One" />
        <mx:Object label="Two" />
        <mx:Object label="Three" />
        <mx:Object label="Four" />
        <mx:Object label="Five" />
        <mx:Object label="Six" />
        <mx:Object label="Seven" />
        <mx:Object label="Eight" />
        <mx:Object label="Nine" />
        <mx:Object label="Ten" />
    </mx:Array>

    <mx:Array id="dp">
        <mx:Object label="default (undefined)"
                data="{undefined}" />
        <mx:Object label="tracklessScrollBar"
                data="tracklessScrollBar" />
    </mx:Array>

    <mx:ApplicationControlBar dock="true">
        <mx:ToggleButtonBar id="toggleButtonBar"
                dataProvider="{dp}"
                itemClick="toggleButtonBar_itemClick(event);" />
    </mx:ApplicationControlBar>

    <mx:List id="list"
            dataProvider="{arr}"
            rowCount="6"
            width="100" />

</mx:Application>

View source is enabled in the following example.

You can also set the verticalScrollBarStyleName style in an external .CSS file or <mx:Style /> block, as seen in the following snippet:

<mx:Style>
    List {
        verticalScrollBarStyleName: tracklessScrollBar;
    }

    .tracklessScrollBar {
        trackSkin: ClassReference(null);
    }
</mx:Style>

Or, you can set the verticalScrollBarStyleName style directly within MXML, as seen in the following snippet:

<mx:List id="list"
        dataProvider="{arr}"
        rowCount="6"
        width="100"
        verticalScrollBarStyleName="tracklessScrollBar" />

For more examples of customizing the vertical scroll bar in Flex components, see http://blog.flexexamples.com/tag/verticalscrollbarstylename/.

 
About The Author

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.

Leave a Reply

Your email address will not be published.

You may 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