Groups | Blog | Home
all groups > flash actionscript > october 2005 >

flash actionscript : Volume slider challenge


Astonished Man
10/6/2005 7:52:59 PM
Maybe some of you gurus can lend a brain to my plight. I have a Flash audio
player that I have created. I like the way it is set up. Basically the
organization is this:
Main movie contains 10 selection buttons, a play button, and a pause button.
When the movie loads it creates a movie clip called "Song" and loads the first
song (each song is its own .swf so that titles and the lited button can
accompany the audio.) As each song is completed it loads the next song into
the movie clip "Song".

Now the fun. I have a speaker icon on the stage and I wanted to click on the
speaker and a pop-up volume slider will appear allowing you to adjust the
volume. Well, it pops up and you can slide it up and down like a champ. It
just doesn't control the volume.

I never could find a tutorial on having a pop-up volume slider that controls
the volume on a movie clip so I have cleaned things from different tutorials
that had at least one of the elements. I'm sure it is that I am not making the
connection between the slider and the movie clip audio.

On my first frame I have the code:

this.createEmptyMovieClip("Song", 10);
Song.loadMovie("track0.swf");

on the movie clip of the volume slider I have:

onClipEvent (load) {
top = _y;
bottom = top + 50;
left = _x;
right = _x;
}
onClipEvent (enterFrame) {
if (dragging == true) {
_root.Song.setVolume(100-((_y-top) + 2));
}
}

ActionScript on the symbol is:

on (press) {
startDrag("", false, left, top, right, bottom);
dragging = true;
}

on (release, releaseOutside) {
stopDrag();
dragging = false;
}

It has been a variety of other things as I have tried to get this to work.
That is where it resides right now.

The other issue that I'm not sure of (because I haven't got over this hurdle
yet) is that when you click outside the volume slider making it go away, will
it retain the volume setting and hold that setting until you return and make a
new adjustment.

If anyone can be of any help I would be grateful. I have posted links to
download all the files below. If there are any ideas you like feel free to use
them.

http://www.ibcyouth.org/MOBplayer/MOBplayer.html (to test the player as it
is now)
http://www.ibcyouth.org/MOBplayer/MOBplayer.fla (the fla file for the
player)
http://www.ibcyouth.org/MOBplayer/track0.fla (the fla file for
the first audio track)
http://www.ibcyouth.org/MOBplayer/track0.swf (the ten audio tracks)
http://www.ibcyouth.org/MOBplayer/track1.swf
http://www.ibcyouth.org/MOBplayer/track2.swf
http://www.ibcyouth.org/MOBplayer/track3.swf
http://www.ibcyouth.org/MOBplayer/track4.swf
http://www.ibcyouth.org/MOBplayer/track5.swf
http://www.ibcyouth.org/MOBplayer/track6.swf
http://www.ibcyouth.org/MOBplayer/track7.swf
http://www.ibcyouth.org/MOBplayer/track8.swf
http://www.ibcyouth.org/MOBplayer/track9.swf
Jon Moyles
10/7/2005 12:00:00 AM
hi
sorry i'm not altering the variable names right now. but heres my code
for a volume slider. you can hopefully find the bits your looking for in it.

theBar.slider._y = 75 - (_parent._parent._parent.theSound.getVolume() *
(3/4));
trace("sound = " + _parent._parent._parent.theSound.getVolume());

theBar.slider.onPress = function(){
startDrag(theBar.slider, false, -7,0,-7,75);
dragging =true;
trace("whiteButton called");
}
whiteButton.onMouseUp = function(){
stopDrag();
if(dragging){
dragging = false;
sndLvl = Math.round(100 - (theBar.slider._y * (4/3)));
_parent._parent._parent.theSound.setVolume(sndLvl);
trace("sndLvl = " + sndLvl);
}else{
_parent.gotoAndPlay("standard");
}
trace("stopDrag called");
}
whiteButton.onPress = function(){
theBar.slider._y = theBar._ymouse;
startDrag(theBar.slider, false, -7,0,-7,75);
dragging =true;
trace("whiteButton called");
}

the whiteButton.onMouseUp function contains the code you need, though
obviouly a lot of details need to be changed. if you get stuck, i might
have more time later in the day to modify the code.

luck
Astonished Man
10/7/2005 12:00:00 AM
Oh, and do you have a link to a site where you have implimented this. Sometimes it helps me to understand code when I can see it in action.

Astonished Man
10/7/2005 12:00:00 AM
400$
10/7/2005 12:00:00 AM
I didn't read ur code... bit in a rush.But to connect ur slider with music
volume.
say u have slider bgMusic
bgMusic._y =(musicVolume/2)
bgMusic.onEnterFrame = function(){
soundObject.setVolume(musicVolume);
musicVolume = bgMusic._y *x;
}
x that I u to need to calculate coz i don't know how tall is ur slider coz
volume goes from 0 to 100.
need to take care of the - sign if movt is upwards.

hope it helps.
Astonished Man
10/7/2005 9:10:49 PM
Thanks. I'll see if I can glean something from that.

Jon Moyles
10/10/2005 12:00:00 AM
well, its still in testing but here:

http://members.iinet.net.au/~rcwright/confined_spaces/

i warn you, this site is not for dial up. oh, no, not at all.

AddThis Social Bookmark Button