Internet Commerce

Partners & Affiliates

Developer Channel


Featured Flash FLA
Gallery Downloads 11401 Flash Movies | 5 New Flash Movies Added
What's New | Top 100

Featured FLA

»  Author: Nick Kouvaris
»  Title: Znax
»  Description: Znax is a board game. Click 4 tiles of the same color and form squares as big as you can. You will erase all the tiles inside the square and collect points. Get maximum score if you make a square with game edges.
»  More by: Nick Kouvaris


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 4941 Flash Sites | 1 New Flash Links
What's New | Top 100 Flash Site

Featured Site

»  Author Agence WOP Digital Agency
»  Title: Electricdrum
»  Description: French WOP Agency, 3D websites, Flash (Papervision, Away 3D), event or institutional projects. The agency operates on all digital projects: consulting, design, graphic design, development, online communication. The WOP agency follows you on the implementation of original, creative and optimized digital projects.


Random Links | Add your own Flash Related Links
Flash Tutorials 1481 Tutorials 7 New Tutorials Added!
What's New | Top100

» How To Make A Simple Animation Using Christmas Clips
» Simple Step by step flash game tutorial Spot the diffrence
» How To Make A Moving Text Slide
» Create Flash Banner With Text Float Effect
» How To Make Zoo Photos Slideshow
» How To Make A Dolphin Photos Slideshow
» How To Make A Fathers Day Slideshow
» How To Make A Transparent Background of Your Flash File
» Create Flash Banner With Text Disco Light Effect Today we will introduce you a Text Disco Light eff
» Unknown Tag: Title10
Random Tutorial | Add Site


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Audio

Categories How to Use Flash MX Sound Objects
Author: Kenny Bellew | Website: http://www.cowfly.com |

 
Page 11
«prev ... 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ... next»

How to Build a Vertical Volume Slider

It is fairly easy to figure out the code for a vertical volume slider that slides 100 pixels. However, what if you wanted your volume slider to be larger or smaller than 100 pixels? The code for this more complex (especially the formula for volCalc below). This one should respond automatically to changes in vertical height of the drag distance.

Fig. 07: Example of vertical volume slider

In this movie, a draggable knob with an instance name of vslider is positioned on top of another movie (the blue reticulated base). The base has the instance name of vbase. All of the code for volume control is placed in clip events of the movie vslider.

The knob, vslider, will automatically position itself in the center of the base (called "vbase" here). The variable "top" represents the uppermost limit for the slider. Since the slider is automatically centered over vbase, the top is set to be the slider's current position plus half the height of vbase (which can be any height).

In the load clip event, the exact height and x coordinate is set to make sure that there is no sub-pixel shift when published.

The volume is then set to: (_y-volCalc)*(-100/(_root.vbase._height))

This code is placed on the sliding knob movie (the red slider in the middle)

onClipEvent(load) {
//_root.vbase._height=200;
//_root.vbase._x=34;
this._y = _root.vbase._y + _root.vbase._height/2 - this._height/2;
left=this._x
top= this._y + _root.vbase._height/2
right=this._x
bottom=this._y - _root.vbase._height/2
volCalc=_y+ _root.vbase._height/2;
}
//End of onClipEvent load
onClipEvent(enterFrame) {
volCalc2=(_y-volCalc)*(-100/(_root.vbase._height));
_root.myMusic.setVolume(volCalc2);
_root.currentVolumeText="Volume: " + _root.myMusic.getVolume();
}
//End of onClipEvent enterFrame
onClipEvent(mouseDown) {
startDrag(this, false, left, top, right, bottom)
}
//
onClipEvent(mouseUp) {
this.stopDrag();
}

// The following is a line by line explanation of the above.

onClipEvent(load) {
This code uses the clip events of a movie clip on stage.
//_root.vbase._height=200;
//_root.vbase._x=34;
//Optionally, use the above to set the height and x position of the slider base.

this._y = _root.vbase._y + _root.vbase._height/2 - this._height/2;
//This sets the knob exactly in the middle of the vbase.

left=this._x
// This will keep the knob from moving any further left.

top= this._y + _root.vbase._height/2
// This set the upper limit that the knob can be moved.

right=this._x
//This keeps the knob from moving any further right.

bottom=this._y - _root.vbase._height/2
//This keeps the knob from moving any further down than half the height of vbase.

volCalc=_y+ _root.vbase._height/2;
// This set the variable volCalc to equal the knob's current position
// plus half of the height (whatever it may be) of the vbase.
}
//End of onClipEvent load
//
onClipEvent(enterFrame) {
volCalc2=(_y-volCalc)*(-100/(_root.vbase._height));
// Thanks, prisma for help with the above line. This take the current knob position
//subtracts the value of volCalc, and multiplies it by -100 divided by the height of vbase.

_root.myMusic.setVolume(volCalc2);
// Sets the new volume level

_root.currentVolumeText="Volume: " + _root.myMusic.getVolume();
// Update a dynamic text box
}
//End of onClipEvent enterFrame
onClipEvent(mouseDown) {
startDrag(this, false, left, top, right, bottom)
//uses the values set in the load clip event to constrain the knob movement to set values.
}
//
onClipEvent(mouseUp) {
this.stopDrag();
}

Note: If your volume is one unit off (it slides up to 101, for example), change the height of your slider so that it is an even number, and make sure your vbase is on a whole even number on its Y-axis, and make the height of vbase an even number.

«prev ... 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ... next»

» Level Intermediate

Added: : 2004-10-12
Rating: 8.48 Votes: 31
Hits: 1294
» 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.
Download (12927 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments