Scrollbar

Scrollbar widget.  The current implementation is a vertical scrollbar suitable for scrolling a multiline text field up and down.  Scroll events can be generated and handled from mouse clicks, drags and programatically from events such as mouse wheel rolls in a text field.

See ScriptField for an example of a widget using the scrollbar.

Summary
ScrollbarScrollbar widget.
Public static constants
DEFAULT_WIDTHWidth of the scrollbar
Private constants
DEFAULT_HEIGHTHeight of the scrollbar buttons and slider
Private positional members
curPosCurrent position of the scrollbar slider
minPosMinimum position of the scrollbar slider
maxPosMaximum position of the scrollbar slider
incPosIncrement/decrement used when the up/down buttons are clicked
Private display members
backgroundScrollbar background area.
upButtonScrollbar up button.
downButtonScrollbar down button.
sliderScrollbar slider.
Private data members
backHeightHeight of the background area (includes buttons).
callbackCallback function called when the scrollbar changes position
isDraggingSet to true when the slider is being dragged
Constructor
ScrollbarCreates a vertical scrollbar suitable for a multiline text field.
Positional methods
setMinMaxSets the minimum and maximum values for the scrollbar.
positionSliderChanges the slider position to the new position which must be in the min/max interval.
positionSliderMouseRelativeCalculates a new slider position based on the mouse y position relative to the slider background and updates the slider position accordingly.
Widget event methods
moveUpCalled when the upButton is clicked, causes the slider position to be incremented.
moveDownCalled when the downButton is clicked, causes the slider position to be incremented.
Mouse event methods
onMouseDownCalled when the mouse is button is pressed down.
onMouseMoveCalled when the mouse is moved over the scrollbar.
onMouseUpCalled when the mouse is button is released.
onMouseOutCalled when the mouse is moved outside a scrollbar sprite.
WidgetInterface
activeSets the state of the widget to active or inactive.
activateActivates the widget, adds its event listeners
disactivateDisactivates the widget, removes its event listeners
disposeDispose of all resources used or referenced in the instance.
destructorRemoves used resources, references and graphics

Public static constants

DEFAULT_WIDTH

public static const DEFAULT_WIDTH: uint

Width of the scrollbar

Private constants

DEFAULT_HEIGHT

private const DEFAULT_HEIGHT: uint

Height of the scrollbar buttons and slider

Private positional members

curPos

private var curPos: Number

Current position of the scrollbar slider

minPos

private var minPos: Number

Minimum position of the scrollbar slider

maxPos

private var maxPos: Number

Maximum position of the scrollbar slider

incPos

private var incPos: Number

Increment/decrement used when the up/down buttons are clicked

Private display members

background

private var background: Sprite

Scrollbar background area.

upButton

private var upButton: ShapeButton

Scrollbar up button.

downButton

private var downButton: ShapeButton

Scrollbar down button.

slider

private var slider: Sprite

Scrollbar slider.

Private data members

backHeight

private var backHeight: uint

Height of the background area (includes buttons).

callback

private var callback: Function

Callback function called when the scrollbar changes position

isDragging

private var isDragging: Boolean

Set to true when the slider is being dragged

Constructor

Scrollbar

public function Scrollbar(owner: String,  
height: uint,  
minValue: Number,  
maxValue: Number,  
increment: Number,  
positionHandler: Function,  
frontColor: uint = Color.Grey,
backColor: uint = Color.DarkGrey)

Creates a vertical scrollbar suitable for a multiline text field.

Parameters

ownername of registered owner (see <WidgetSprite.register>)
heightheight of the scrollbar in pixels
minValueminimum (top) value
maxValuemaximum (bottom) value
incrementvalue added or subtracted from the current position when the up/down buttons are used
positionHandlera callback function that is called when the scrollbar position is changed
frontColorbase theme color for the buttons and slider
backColorbase theme color for the background

Callbacks

positionHandlerfunction onScrollbarPositionChange(newPosition:Number):void

Positional methods

setMinMax

public function setMinMax(minValue: Number,
maxValue: Number):void

Sets the minimum and maximum values for the scrollbar.

Parameters

minValuesmallest positional value (top)
maxValuelargest positional value (bottom)

positionSlider

public function positionSlider(newPosition: Number):void

Changes the slider position to the new position which must be in the min/max interval.

Parameters

newPositiona value in the min to max interval.

positionSliderMouseRelative

private function positionSliderMouseRelative():void

Calculates a new slider position based on the mouse y position relative to the slider background and updates the slider position accordingly.

Widget event methods

moveUp

private function moveUp():void

Called when the upButton is clicked, causes the slider position to be incremented.

moveDown

private function moveDown():void

Called when the downButton is clicked, causes the slider position to be incremented.

Mouse event methods

onMouseDown

private function onMouseDown(event: MouseEvent):void

Called when the mouse is button is pressed down.  If the mouse is over the slider then a dragging operation is started.  If the mouse is over the slider background then the slider position is updated.

Parameters

eventa mouse event

onMouseMove

private function onMouseMove(event: MouseEvent):void

Called when the mouse is moved over the scrollbar.  If the slider is being dragged then the slider position is updated.

Parameters

eventa mouse event

onMouseUp

private function onMouseUp(event: MouseEvent):void

Called when the mouse is button is released.  If the slider was being dragged then the slider position is updated and the dragging operation is stopped.

Parameters

eventa mouse event

onMouseOut

private function onMouseOut(event: MouseEvent):void

Called when the mouse is moved outside a scrollbar sprite.  If the mouse is moved to a non-scrollbar item then any ongoing dragging operation is stopped.

Parameters

eventa mouse event

WidgetInterface

active

public function set active(state: Boolean):void

Sets the state of the widget to active or inactive.

Parameters

stateTrue to activate, false otherwise.

activate

private function activate():void

Activates the widget, adds its event listeners

disactivate

private function disactivate():void

Disactivates the widget, removes its event listeners

dispose

public function dispose():void

Dispose of all resources used or referenced in the instance.

destructor

private function destructor():void

Removes used resources, references and graphics

Widgets are required to implement this interface.
Base class for widgets to enable/disable event listeners and keep a global tab order of all widgets (provided they are created and registered in tab order.
public static const DEFAULT_WIDTH: uint
Width of the scrollbar
private const DEFAULT_HEIGHT: uint
Height of the scrollbar buttons and slider
private var curPos: Number
Current position of the scrollbar slider
private var minPos: Number
Minimum position of the scrollbar slider
private var maxPos: Number
Maximum position of the scrollbar slider
private var incPos: Number
Increment/decrement used when the up/down buttons are clicked
private var background: Sprite
Scrollbar background area.
private var upButton: ShapeButton
Scrollbar up button.
private var downButton: ShapeButton
Scrollbar down button.
private var slider: Sprite
Scrollbar slider.
private var backHeight: uint
Height of the background area (includes buttons).
private var callback: Function
Callback function called when the scrollbar changes position
private var isDragging: Boolean
Set to true when the slider is being dragged
public function Scrollbar(owner: String,  
height: uint,  
minValue: Number,  
maxValue: Number,  
increment: Number,  
positionHandler: Function,  
frontColor: uint = Color.Grey,
backColor: uint = Color.DarkGrey)
Creates a vertical scrollbar suitable for a multiline text field.
public function setMinMax(minValue: Number,
maxValue: Number):void
Sets the minimum and maximum values for the scrollbar.
public function positionSlider(newPosition: Number):void
Changes the slider position to the new position which must be in the min/max interval.
private function positionSliderMouseRelative():void
Calculates a new slider position based on the mouse y position relative to the slider background and updates the slider position accordingly.
private function moveUp():void
Called when the upButton is clicked, causes the slider position to be incremented.
private function moveDown():void
Called when the downButton is clicked, causes the slider position to be incremented.
private function onMouseDown(event: MouseEvent):void
Called when the mouse is button is pressed down.
private function onMouseMove(event: MouseEvent):void
Called when the mouse is moved over the scrollbar.
private function onMouseUp(event: MouseEvent):void
Called when the mouse is button is released.
private function onMouseOut(event: MouseEvent):void
Called when the mouse is moved outside a scrollbar sprite.
public function set active(state: Boolean):void
Sets the state of the widget to active or inactive.
private function activate():void
Activates the widget, adds its event listeners
private function disactivate():void
Disactivates the widget, removes its event listeners
public function dispose():void
Dispose of all resources used or referenced in the instance.
private function destructor():void
Removes used resources, references and graphics
A multi-line text field with optional syntax highlighting for scripts written in the ActionScript 3/haxe, xml/flex/degrafa/svg/xaml or ruby/hotruby.
Close