View Full Version : Flash Video Components: Connect VolumeBar and Mute Button
forma3
07-03-2007, 06:16 PM
I'm putting together a custom Flash video and audio player using the FLV playback components.
Almost everything is working fine, but I want to sync the "VolumeBar" and "Mute Button" components, so when a user clicks the mute button the volume bar is set to zero and vice versa (clicking unmute moves the handle to the right).
Also, if the user moves the volume bar handle to the left (off) the mute button should also show as muted. Most of the FLV players that use the components seem to have this problem. The player on Forbes.com, http://www.forbes.com/ , is the single component-based (presumably) exception I've seen thus far.
My player: http://dev.forma3.com/dos/fplayer/player_v1.2.html
Source FLA: http://dev.forma3.com/dos/fplayer/player_v1.2.fla
No doubt this is pretty simple to do, but I haven't been able to find the solution searching through the web or forums.
Thanks in advance!
LOLFlash
07-05-2007, 02:47 AM
You have to create listener: running process like interval and check condition of volume and mute all the time
forma3
07-05-2007, 03:29 PM
Ah, thanks. Good idea.
If I figure it out, I'll post the code since others may find this useful.
forma3
07-05-2007, 07:27 PM
I've created a partial solution to this, but its not without a few small problems.
Here is the code:
checkVolume = function() {
if( video.volume == 0) {
myMuteButton.on_mc._visible = false;
myMuteButton.off_mc._visible = true;
volumeBarHandle_mc._x = myVolumeBar._x;
myVolumeBar.fullness_mc._visible = false;
} else {
myMuteButton.on_mc._visible = true;
myMuteButton.off_mc._visible = false;
myVolumeBar.fullness_mc._visible = true;
}
}
setInterval(checkVolume, 400);
The idea behind this is really simple, the function checks the volume and, if its zero (muted), moves the handle to the left, hides the "fullness" movie clip and volume on button. When the volume is higher then zero, it basically does the reverse.
There is one main problem: when the user has set the volume to zero, and the slider moves all the way to the left, it can be a little "sticky" when moving the handle to the right.
The SWF is seeing the volume is zero and trying to move the slider back to the left. When the interval is lower (say, 100) then it cycles too fast for the user to increase the volume and get the handle "unstuck". At 400 this isn't as much of a problem, but there are still intermittent problems.
I've tried adding a mouseDown check and a listener object to the handle and VolumeBar, but can't get either to report a mouse down.
Thoughts?
Here is the complete code and example:
My player: http://dev.forma3.com/dos/fplayer/player_v1.2.html
Source FLA: http://dev.forma3.com/dos/fplayer/player_v1.2.fla
Thanks!
LOLFlash
07-05-2007, 07:39 PM
remove interval
and set it back if myVolumeBar._x > 10?
forma3
07-05-2007, 08:24 PM
Hum, not sure I follow.
The interval is used to change both the mute button and the volume bar so, by removing it, I'd have to have something else watching the volume bar position or if the mute button was pressed. Correct?
LOLFlash
07-05-2007, 09:17 PM
I didnt think about it sry
try:
checkVolume = function() {
if (volumeBarHandle_mc.hitTest(_xmouse, _ymouse, false)) return;
if( video.volume == 0) {
myMuteButton.on_mc._visible = false;
myMuteButton.off_mc._visible = true;
volumeBarHandle_mc._x = myVolumeBar._x;
myVolumeBar.fullness_mc._visible = false;
} else {
myMuteButton.on_mc._visible = true;
myMuteButton.off_mc._visible = false;
myVolumeBar.fullness_mc._visible = true;
}
}
setInterval(checkVolume, 400);
forma3
07-06-2007, 05:55 PM
First off, thanks for the great help LOLFlash.
I think I finally figured it out.
Here is the code:
checkVolume = function() {
_root.onMouseDown = function() {
if (!videoMuteButton.hitTest(_xmouse, _ymouse)) mouseHold = true;
};
_root.onMouseUp = function() { mouseHold = false; };
if (video.volume == 0 && !mouseHold) {
videoMuteButton.on_mc._visible = false;
videoMuteButton.off_mc._visible = true;
volumeBarHandle_mc._x = videoVolumeBar._x;
videoVolumeBar.fullness_mc._visible = false;
} else {
videoMuteButton.on_mc._visible = true;
videoMuteButton.off_mc._visible = false;
videoVolumeBar.fullness_mc._visible = true;
}
}
setInterval(checkVolume, 100);Your hittest suggestion pointed me in the right direction. The small issue with just the hittest though is that when the user makes the change using the slider, and their cursor is still over the handle, the slider and mute button MCs will not update. Since they have unclicked the handle, this is a bit confusing since it makes it look like their change didn't register.
So, I added a global mouseDown check to ensure that when the user was clicking the script wouldn't prevent them from moving the slider. The problem with this method is it interferes with the mute button, so I added the hittest to ensure the user is not using the mute.
Its a bit verbose, but I guess it works alright.
Here's the updated code if anyone is interested:
Player: http://dev.forma3.com/dos/fplayer/player_v1.2.html
Source FLA: http://dev.forma3.com/dos/fplayer/player_v1.2.fla
Thanks again for all your help!
wizardofoz
11-25-2009, 06:11 PM
Any idea how to get the exact same thing working in as3.0?
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.