音量滑块 - 鼠标悬停之前音量不会改变

发布于 2024-08-11 11:19:51 字数 1793 浏览 8 评论 0原文

我创建了一个带有滑动音量控制的小型音乐播放器。我的音量有问题。虽然它确实可以正确控制音量,但如果我将初始音量设置为小于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上得阳光 2024-08-18 11:19:51

您需要使用初始值调用 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.

云巢 2024-08-18 11:19:51

刚刚用这段代码修复了:

mySound_sound.onLoad = function(){
    mySound_sound.setVolume(-1 * song_volume);
}

现在效果很好!

Just fixed with this code:

mySound_sound.onLoad = function(){
    mySound_sound.setVolume(-1 * song_volume);
}

Works great now!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文