First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Kenny Bellew | Website:

How to Build a Horizontal Volume Slider

  1. Create two images: the base of your slider interface and the image that will slide. If convenient, make the base of your slider 100 pixels wide, as the width would then correspond exactly to the volume range.
  2. Place both on stage as movie clips on separate layers. Place the base so that both axis's are on an integer (whole number).
  3. From the pull-down top menu, select "View" and then "Rulers".
  4. Place your slider image, exactly in the middle of the base. This point will represent volume at 50%. Place the slider so that both axis's are on an integer (whole number).
  5. Give your slider movie clip the instance name of "hslider".
  6. Select your slider movie clip, press F9 to access actions for the movie clip and add the following (of course, remove the "//" comments if desired):
Fig. 06: Example of horizontal volume slider
onClipEvent(load) {
this._x=_root.hbase._x + _root.hbase._width/2 - this._width/2;
left=this._x - _root.hbase._width/2;
right=this._x + _root.hbase._width/2;
volCalc=_root.hslider._x - _root.hbase._width/2
//End of Clip Event Load
onClipEvent(mouseDown) {
startDrag(this, false, left , top , right, bottom)
onClipEvent(mouseUp) {
onClipEvent(enterFrame) {
// This constantly sets the current a-axis position of
//the slider to "sliderx
sliderx=_root.hslider._x; //Sets sliderx as variable for a-axis of slider
myMusicVolume=(sliderx-volCalc); //The value of x-axis load value - n = 50
_root.currentVolume="Volume " + _root.myMusic.getVolume();

In the above example, the slider movie clip can now be dragged from its center starting point to both ends of the base image. The variable "sliderx" is defined to equal the current x-axis point of your slider movie clip each time a frame is processed. The goal is to position your slider movie clip graphic so that its x-axis starts directly in the middle of the base. That way, you can calculate 50 pixels when the slider slides to the right and 50 pixels when it slides to the left.

The ActionScript for the above could also be placed in an event handler on a frame of any movie clip that loops such as:

this.onEnterFrame = function () {
//Your code here

Use whatever is most convenient.    
» Level Intermediate

Added: 2004-10-12
Rating: 8 Votes: 31
(10 being the highest)
» Author
Kenny Bellew is a technical writer and freelance flash programmer who specializes in Flash audio. He lives in Minneapolis, MN.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.