音量滑块 - 鼠标悬停之前音量不会改变
我创建了一个带有滑动音量控制的小型音乐播放器。我的音量有问题。虽然它确实可以正确控制音量,但如果我将初始音量设置为小于 100%,则音量始终从 100% 开始,直到我将鼠标移到播放器上。此时,音量将更改为初始音量设置的值。
这是一个闪存错误,还是我错过了什么?
以下是受影响的代码(为简洁起见,省略了其他按钮/功能的代码):
var song_initvolume:Number = 100;
slider_1._x = groove_1._x + song_initvolume;
playSong(0,song_play);
slider_1.onPress = function() {
this.startDrag(true, groove_1._x, groove_1._y, groove_1._x + 96, groove_1._y);
}
slider_1.onRelease = function() {
this.stopDrag();
}
slider_1.onMouseMove = function(){
newPoint = new Object();
newPoint.x = this._x;
newPoint.y = this._y;
groove_1.globalToLocal(newPoint);
mySound_sound.setVolume(-1 * newPoint.x);
}
function playSong(songNum,songPlay,reset_Pos){
if(reset_Pos){
mySound_sound = new Sound();
}
var myTitle = mySongs_array[songNum].TITLE;
trace("Playing TITLE= " + myTitle);
var myArtist = mySongs_array[songNum].ARTIST;
trace("Playing ARTIST= " + myArtist);
var myURL = mySongs_array[songNum].URL;
trace("Playing URL= " + myURL);
title_txt.text = mySongs_array[songNum].TITLE;
artist_txt.text = mySongs_array[songNum].ARTIST;
mySound_sound.loadSound(myURL,songPlay);
// start oncomplete
mySound_sound.onSoundComplete = function() {
song_pos = 0;
reset_Pos = true;
if(song_continuous){
song_play = true;
current_song++;
if (current_song>=my_total){
current_song=0;
if(song_loop){
song_play = true;
} else {
song_play = false;
}
}
} else {
song_play = false;
}
playSong(current_song,song_play,reset_Pos);
}
// end oncomplete
}
我希望能够将音量设置为 50%,但每次都会发生上述行为。
任何想法都将不胜感激。
I've created a small music player with a sliding volume control. I'm having trouble with the volume. Though it does control volume properly, if I set the initial volume to less than 100%, the volume always starts at 100% until I move my mouse over the player. At that point, the volume changes to whatever the initial volume is set to.
Is this a flash bug, or am I missing something?
Here is the affected code (code for other buttons/functions omitted for brevity):
var song_initvolume:Number = 100;
slider_1._x = groove_1._x + song_initvolume;
playSong(0,song_play);
slider_1.onPress = function() {
this.startDrag(true, groove_1._x, groove_1._y, groove_1._x + 96, groove_1._y);
}
slider_1.onRelease = function() {
this.stopDrag();
}
slider_1.onMouseMove = function(){
newPoint = new Object();
newPoint.x = this._x;
newPoint.y = this._y;
groove_1.globalToLocal(newPoint);
mySound_sound.setVolume(-1 * newPoint.x);
}
function playSong(songNum,songPlay,reset_Pos){
if(reset_Pos){
mySound_sound = new Sound();
}
var myTitle = mySongs_array[songNum].TITLE;
trace("Playing TITLE= " + myTitle);
var myArtist = mySongs_array[songNum].ARTIST;
trace("Playing ARTIST= " + myArtist);
var myURL = mySongs_array[songNum].URL;
trace("Playing URL= " + myURL);
title_txt.text = mySongs_array[songNum].TITLE;
artist_txt.text = mySongs_array[songNum].ARTIST;
mySound_sound.loadSound(myURL,songPlay);
// start oncomplete
mySound_sound.onSoundComplete = function() {
song_pos = 0;
reset_Pos = true;
if(song_continuous){
song_play = true;
current_song++;
if (current_song>=my_total){
current_song=0;
if(song_loop){
song_play = true;
} else {
song_play = false;
}
}
} else {
song_play = false;
}
playSong(current_song,song_play,reset_Pos);
}
// end oncomplete
}
I'd like to be able to set the volume at say 50%, but the above mentioned behavior happens each time.
Any ideas are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用初始值调用 mySound_sound.setVolume() 。现在您只需在 onMouseMove 处理程序中执行操作。
You need to call mySound_sound.setVolume() with your initial value. Right now you only do in in the onMouseMove handler.
刚刚用这段代码修复了:
现在效果很好!
Just fixed with this code:
Works great now!