Tag Scrollbar
Flex 3: disable scrollbar in a List
De List control in Flex 3 beschikt over de mogelijkheid de scrollbar te beïnvloeden. Dit is echter beperkt tot horizontalScrollPolicy & verticalScrollPolicy. Met deze twee property’s kan je bepalen of je de scrollBar al dan niet toont.
Maar ik wou – bij het aanpassen van een item uit de list – niet dat de scrollBar zou verdwijnen, maar disabled zou worden. Dit resultaat heb ik bereikt door gebruik te maken van volgende methode:
var lSubtitles:CustomList = new CustomList();
lSubtitles.enableScrollBar(false);
// Invalidate the CustomList so the applications knows
// he needs to refresh the list
lSubtitles.invalidateList();
De klasse:
package classes.views.subtitles.list
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.controls.List;
import mx.controls.scrollClasses.ScrollBar;
// This custom list is programmed to be able to disable
// the scrollbar which is by default impossible.
// This is a useful addition to the current
// functionality of ScrollPolicy OFF|ON|AUTO
// (which hides/shows the scrollbar)
public class CustomList extends List
{
private var _bEnabledScrollBar:Boolean = true;
// Constructor
public function CustomList()
{
super();
}
// Function to set whether the scrollbar should
// be put enabled or disabled
public function enableScrollBar(bValue:Boolean):void
{
_bEnabledScrollBar = bValue;
if(!bValue)
{
// This is the event which is triggered when a
// user scrolls with his mouse wheel.
// Check if this object has such an event listener
if(super.hasEventListener(MouseEvent.MOUSE_WHEEL))
{
// This is the protected event handler which
// resides inside the ListBase
super.removeEventListener(MouseEvent.MOUSE_WHEEL,
mouseWheelHandler);
}
}
else
{
// This is the event which is triggered when a user
// scrolls with his mouse wheel. Make sure this
// doesn't has such an event listener
if(!super.hasEventListener(MouseEvent.MOUSE_WHEEL))
{
// This is the protected event handler which
// resides inside the ListBase
super.addEventListener(MouseEvent.MOUSE_WHEEL,
mouseWheelHandler);
}
}
}
// The configure scrollbar method manages
// the functionality of the scrollbars this method
// get's called when the invalidateDisplayList is called
protected override function configureScrollBars():void
{
// If the _bDisabledScrollBar boolean is set to true;
// the scrollbar should be disabled!
if(!_bEnabledScrollBar)
{
// Loop trough the children of the list and
// find the scrollbar
for(var t:int = 0; t < this.numChildren; t++)
{
if(this.getChildAt(t) is ScrollBar)
{
var sb:ScrollBar = this.getChildAt(t) as ScrollBar;
sb.enabled = false;
sb.mouseEnabled = false;
this.mouseEnabled = false;
}
}
}
// Else just use the default behavior of the list
else
{
super.configureScrollBars();
}
}
}
}
Een screenshot van het resultaat:

