views:

79

answers:

2

Hi all,

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.

+1  A: 

You need to call mySound_sound.setVolume() with your initial value. Right now you only do in in the onMouseMove handler.

Parappa
Should have mentioned that I had that code in there as well then, before the song plays for the first time, these lines:song_volume = -1 * song_volume;mySound_sound.setVolume(song_volume);No worky!
BumbleBob
+1  A: 

Just fixed with this code:

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

Works great now!

BumbleBob