Access keys

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: Saturday, 07 October 2006, 23:53:41
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 broadcast to listeners:
SliderEvent with type: ON_SLIDE_DONE
SliderEvent with type: ON_SLIDE - if position changes

Constructor

Slider

function Slider (
)
Creates a new Slider.

Class properties

ASCENDING

static ASCENDING:Number = 1
(read,write)
Top or left is max value.

DESCENDING

static DESCENDING:Number = -1
(read,write)
Bottom or right is max value.

Instance methods

getDirection

function getDirection (
) : Number
Gets the direction of the Slider.
Returns:
A Number value; either ASCENDING or DESCENDING.

getValue

function getValue (
) : Number
The current percentage value of the slider.
Returns:
A Number between 0 and 100.

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 broadcast to listeners:
SliderEvent with type: ON_SLIDE_DONE