Slider

Kind of class:class
Inherits from:DragButton < EventMovieClip < MovieClip
Author:Martijn de Visser, Arthur Clemens (refactoring)
Classpath:org.asapframework.ui.slider.Slider
File last modified:Tuesday, 21 November 2006, 11:08:34
A class to create a basic slider with, should be attached to slider knob MovieClip.
Slider sends events on dragging and releasing the slider knob, with values between 0 and 100 percent.
Usage:
  • The knob movieclip slider_knob_vertical_mc is set to class org.asapframework.ui.slider.Slider. The bar movieclip slider_bar_vertical_mc is set to org.asapframework.ui.buttons.EventButton.
    //import flash.geom.*;
    // Still support Flash 7:
    import org.asapframework.util.types.*;
    
    import org.asapframework.ui.slider.*;
    import org.asapframework.ui.buttons.EventButtonEvent;
    import org.asapframework.util.RectangleUtils;
    import org.asapframework.events.EventDelegate;
    
    // slider bar
    mSliderBar = timeline.slider_bar_vertical_mc;
    // react on clicks in the bar
    mSliderBar.addEventListener(EventButtonEvent.ON_RELEASE, EventDelegate.create(this, handleBarClick));
    
    // slider
    mSlider = timeline.slider_knob_vertical_mc;
    // at 0 percent, the knob is placed at the top
    mSlider.setDirection(Slider.DESCENDING);
    // set the knob bounds to the slider bar bounds
    var bounds:Rectangle = RectangleUtils.boundsOfMovieClip(mSliderBar);
    // lock to the center of the bar
    RectangleUtils.flattenWidth(bounds);
    mSlider.setBounds(bounds);		
    // update only on slide end
    mSlider.addEventListener(SliderEvent.ON_SLIDE_DONE, EventDelegate.create(this, handleSliderSlideDone));
Events broadcasted to listeners:

Summary


Constructor
Class properties
Instance properties
Instance methods
  • setDirection (inDirection:Number) : Void
    • Sets the direction of the Slider.
  • getDirection : Number
    • Gets the direction of the Slider.
  • setValue (inPercentage:Number) : Void
    • Sets the percentage value of the Slider.
  • setPosition (inPixelPosition:Number) : Void
    • Sets the position of the Slider in pixels relative to the Slider; a position exactly at the top of the Slider will be 0; a position exactly at the bottom of the Slider will be the height of the Slider bounds.
  • getValue : Number
    • The current percentage value of the slider.
  • setBounds (inBounds:Rectangle) : Void
    • Sets the constraining rectangle the slider moves within.
  • update : Void
    • Updates the position of the Slider and sends an ON_SLIDE_DONE event.
  • toString : String
  • updatePosition (inX:Number, inY:Number) : Void
    • Updates the _x or _y position - dependent on the Slider orientation.
  • sendEvent (inEventName:String) : Void
    • Calculates the min and max values before sending event inEventName.
  • updateCurrentPos (inX:Number, inY:Number) : Void
  • updatePercentage (inPercentage:Number) : Void
Event handlers

Constructor

Slider

function Slider (
)

Creates a new Slider.

Class properties

ASCENDING

static ASCENDING:Number = 1
(read)

Top or left is max value.

DESCENDING

static DESCENDING:Number = -1
(read)

Bottom or right is max value.

HORIZONTAL

static private HORIZONTAL:String = "HORIZONTAL"
(read)

VERTICAL

static private VERTICAL:String = "VERTICAL"
(read)

Instance properties

mBounds

private mBounds:Rectangle
(read)

The bounding rectangle that constrains the slider knob movements, in Stage pixels.

mCurrentPos

private mCurrentPos:Point
(read)

mDirection

private mDirection:Number = DESCENDING
(read)

mOrientation

private mOrientation:String = VERTICAL
(read)

Set automatically when setBounds is called.

mPercentage

private mPercentage:Number
(read)

The current position of the Slider knob.

Instance methods

getDirection

function getDirection (
) : Number

Gets the direction of the Slider.
Returns:

getValue

function getValue (
) : Number

The current percentage value of the slider.
Returns:
  • A Number between 0 and 100.

sendEvent

private function sendEvent (
inEventName:String) : Void

Calculates the min and max values before sending event inEventName.
Parameters:

setBounds

function setBounds (
inBounds:Rectangle) : Void

Sets the constraining rectangle the slider moves within.
Parameters:
inBounds:
specify a Rectangle with the same 'y' value for both ends to create a horizontal slider; use a Rectangle with the same 'x' values for a vertical slider

setDirection

function setDirection (
inDirection:Number) : Void

Sets the direction of the Slider.
Parameters:
inDirection:

setPosition

function setPosition (
inPixelPosition:Number) : Void

Sets the position of the Slider in pixels relative to the Slider; a position exactly at the top of the Slider will be 0; a position exactly at the bottom of the Slider will be the height of the Slider bounds.
The position will be translated to a percentage value dependent on the orientation and direction of the Slider.
Parameters:
inPixelPosition:
the position of the Slider in pixels

setValue

function setValue (
inPercentage:Number) : Void

Sets the percentage value of the Slider.
Parameters:
inPercentage:
the percentage value (from 0 to 100)

toString

function toString (
) : String

update

function update (
) : Void

Updates the position of the Slider and sends an ON_SLIDE_DONE event.
Events broadcasted to listeners:

updateCurrentPos

private function updateCurrentPos (
inX:Number, inY:Number) : Void

updatePercentage

private function updatePercentage (
inPercentage:Number) : Void

updatePosition

private function updatePosition (
inX:Number, inY:Number) : Void

Updates the _x or _y position - dependent on the Slider orientation.
Parameters:
inPercentage:
the relative position to move the Slider to; the _x / _y positions are calculated from the percentage value

Event handlers

onClipDragging

private function onClipDragging (
) : Void

Called while dragging.
Events broadcasted to listeners:
  • SliderEvent with type: ON_SLIDE - if position changes
    • (null)

onDragEnd

private function onDragEnd (
) : Void

Called when the dragging is ended.
Events broadcasted to listeners: