| Let's get into the scripting.
Select frame 1 of the actions layer and add
these actions:
bgSound = new
Sound(this);
bgSound.attachSound("sound1");
bgSound.start(0, 99);
playB.enabled=false;
slider.slideBar._y = -50;
slider.slideBar.onEnterFrame = function() {
bgSound.setVolume(0-this._y);
};
slider.slideBar.onPress = function() {
startDrag(this, false, this._x, -65, this._x, 0);
};
slider.slideBar.onRelease = slider.slideBar.onReleaseOutside=function
() {
stopDrag();
};
stopB.onRelease = function() {
bgSound.stop();
playB.enabled=true;
stopB.enabled=false;
};
playB.onRelease = function() {
bgSound.start(0, 99);
playB.enabled=false;
stopB.enabled=true;
};
stop();
Let's go through that bit by bit.
Line 1 - we make a new sound object
on "this" timeline. The "this" is
very important because if you do not
sprecify a target here then flash will
assume we want to make the new object
on level0 which would cause us problems
later on if we wanted to load our sound
slider into another movie.
Line 2 - We attach the sound in our
library to our new sound object. Remember
that "sound1" was the linkage
name that we gave our sound.
Line 3 - We start out sound object.
The "0" represents the number
of milliseconds from the start of the
sound that we want flash to start playing
- 99.9% of the time you will set this
0. The "99" represents the
number of times we want flash to loop
our sound.
Line 4 - Turn off the play button (we
dont need it at the moment because the
sound is already playing).
Line 5 - Set the starting y position
of our slideBar
Lines 6-8 - This tells Flash to set
the volume of our sound object to whatever
the y position of our slideBar is. Now
because we are getting the y value of
the slideBar from within the sliderMC,
we need to convert the negative y value
into a positive number to set the volume
to. We do this with "0-this._y".
So if the slideBar was at a y position
of minus 43 then we would set the volume
of our sound object to 0 - -43 which
= 43.
Lines 9-14 - This sets up the dragging
action for our slideBar and constrains
it to a rectangle.
Lines 15-19 - Our stop button action.
First line stops the sound object. Second
line turns on our play button. Third
line turns off the stop button.
Lines 20-24 - Our play button action.
First line plays the sound object. Second
line turns off our play button. Third
line turns on the stop button.
Save your fla and then test it.
That's about it.
|