Public Properties and Methods of the HorizontalSlider Class

Before we have a look at the code behind the HorizontalSlider class, let us list the public properties and methods of the class. Let us also metion that the VerticalSlider class contained in the package has the same methods and properties. Clearly, vertical sliders can be obtained from horizontal sliders by rotating by 90 degrees. (HorizontalSlider inherits the 'rotation' property of the Sprite class.) The only reason for having the VerticalSlider class lies in the a somewhat different style of drawing some graphical elements, for example, tick marks.

The HorizontalSlider class has one public static constant. ('static' means the contant is the same for every instance of the class). The constant corresponds to the event dispatched when the position of the knob changes as the knob is being dragged by the user:

  • SLIDER_CHANGE:String = "sliderChange"

The HorizontalSlider class has one public, read-only property:

  • instance.isPressed: Boolean   The property is set to 'true' when the user presses the mouse button while over the knob; it is reset to the default 'false' when the user subsequently releases the button over or ourside the knob. (We do not use this property in our Timeline script.)

The HorizontalSlider class has the following public methods:

  • The constructor evoked with the key word 'new' : new HorizontalSlider(len:Number,t:String)  The class constructor takes two parameters: the length of the instance to be created and the style of the knob. The latter can be 'triangle' or 'rectangle'.
     
  • instance.setKnobPos(a: Number): void   The method sets the position of the knob along the slider. The initial position is set to 0.
     
  • instance.getKnobPos(): Number   The method returns the current position of the knob along the slider.
     
  • instance.changeKnobSize(s: Number): void   The method makes it possible to customize the size of a triangular or a rectangular knob. Default: 8 pixels.
     
  • instance.changeKnobColor(c: Number): void   The method changes the color of the knob. Default: dark gray.
     
  • instance.changeKnobOpacity(o: Number): void   The method changes opacity of the knob. Default: 1.0 (completely opaque).
     
  • instance.changeKnobRightLine(c: Number): void   The method changes the color of the right and the bottom outline of the knob.
    Default: black.
     
  • instance.changeKnobLeftLine(c: Number): void   The method changes the color of the left (and the top for a rectangular knob) outline of the knob. Default: white.
     
  • instance.changeTrackOutColor(c: Number): void   The method changes the color of the outline of the slider's track and the tick marks. Default: black.
     
  • instance.changeTrackInColor(c: Number): void   The method changes the color of the inside line of the slider's track.
    Default: white.
     
  • instance.getSliderLen(): Number   The method returns the slider's length.
     
  • instance.destroy(): void   The method (which should be called before removing an instance at runtime) clears all graphics, removes all listeners, and sets objects created by the instance to null.
     

In addition, HorizontalSlider inherits all properties and methods of the Sprite class as it extends Sprite. (In other words, every instance of the HorizontalSlider class is a Sprite).

Download

  • Download 'fla' and 'as' files corresponding to this tutorial: sliders.zip

On the next page, we take a look at some aspects of the code for the HorizontalSlider class.

Back to Bridging the Gap Tutorials              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. To contact us, email Barbara Kaskosz at barbara@flashandmath.com, Doug Ensley at doug@flashandmath.com, or Dan Gries at dan@flashandmath.com.

Adobe®, Flash®, Flex® are registered trademarks of Adobe Systems Incorporated.