|
||||||
|
||||||
Flash - Volume Controls

Free Flash Sound Tutorial
Step Seven: The ActionScript
Place the following ActionScript in frame 1:
myMusic = new
Sound(this);
myMusic.attachSound("mySound");
myMusic.start(0, 99);
slider.control._y = -50;
slider.control.onEnterFrame = function() {
myMusic.setVolume(0-this._y);
}
slider.control.onPress = function() {
startDrag(this, false, this._x, -100, this._x, 0);
}
slider.control.onRelease = function()
{
stopDrag();
}
stopButton.onRelease = function() {
myMusic.stop();
}
playButton.onRelease = function() {
myMusic.start(0, 99);
}
You will want to test your movie as it is now all done.
ActionScript Explained
myMusic = new Sound(this);
Makes a new sound object in the timeline. This sound object does not yet contain
any sound yet. It is like a CD player with out a CD.
myMusic.attachSound("mySound");
This attaches the sound from the Library which we called "mySound".
myMusic.start(0, 99);
This is an auto-start. It instructs the sound file to start to play. (The files
at the top of this page do not have this - on my files you must hit the play
button). Once the file starts to play it will loop 99 times.
slider.control._y =
-50;
Sets the initial volume to 50% full volume. 0 is
off and -100 is full volume. Remember that
-100
is the top of the slider scale (step 2.20 above).
slider.control.onEnterFrame = function()
{
myMusic.setVolume(0-this._y);
}
Sets the volume to be what every the Y value of slider control. As we slide the
controller up and down the volume goes according to the Y value.
The(0-this._y)converts all the negative numbers
to positive so the volume scale is actually 0 to 100 (not 0 to -100).
Note - Rotation: What is strange is that if you rotate the slider on the main stage to make a horizontal control - the symbols nested inside are not considered to have been rotated. This means that the Y value still works! You do not need to convert the ActionScript to an X value.
Note - Size: This same is also true of size. If you change the size of the controller on the main Stage the Y scale inside the re-sized controller is still 0 to -100. The sizing on Stage makes no difference to measurements of objects nested inside a symbol.
slider.control.onPress = function()
{
startDrag(this, false, this._x,
-100, this._x,
0);
}
This makes the slider move when it is dragged with the mouse. Its movement is
restricted between 0 and -100.
slider.control.onRelease = function()
{
stopDrag();
}
When you let go of the mouse the slider will stop moving.
stopButton.onRelease = function()
{
myMusic.stop();
}
When you click on the stop button it will stop the sound from playing.
playButton.onRelease = function()
{
myMusic.start(0,
99);
}
When you click on the play button the sound file will play and loop 99 times.
Well except for some foot notes that's it - I hope you found this tutorial useful.
Note: This method uses in this tutorial is: Event sound
Cross Ref: For a beginners tutorial on the difference between Event and Streamed sound see: Sound
Cross Ref: For a practical tutorial on how to compress Flash movies with embedded sound files see: Optimizing a Flash Movie
|
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
|
|
|
All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.
|