4 Replies Latest reply on Oct 13, 2006 7:13 PM by Dyer55

    Volume & Slider Position When Loaded

    Dyer55
      You people have been so good at helping me and I hope I can get a little direction with this issue as well. First I'll point out that I didnt use components, just my movie clips and coding.

      I made a little mp3 player and so far it works beautifully. The only issue I have is this... When my mp3 player is loaded and begins to play the song, the volume slider is all the way to the left which turns my volume all the way down. Making the user turn up the volume(with my slider) before they can hear anything.

      I want the volume and the slider's position to be at half when it loads, but have the capability to turn down if the user chooses.

      Ive tried to code it in various ways and here are the two issues I have run into....
      ***Either my mp3 loads with the volume at about half which I want but the slider doesn't function.
      ***Or.. if I do get both the volume and slider to load at 50% I am unable to move my slider any lower (just higher) and thus the volume can not be lowered.

      Im wondering if this has to do with the position of the slider as its coded to follow the line on the volume bar...
      Here is my code, I hope its readable. I'm not the best at coding.
        • 1. Re: Volume & Slider Position When Loaded
          S4Potential Level 1
          You problem is with the onEnterFrame event handler. It's executed each time a frame is entered. A frame is entered as many times per seconds as you frame rate is set and this even if you have only one frame in your timeline or even if you issued a stop command. Thus, reseting your volume to 50 non stop.

          Replace it with the Sound.onLoad event handler which will be executed only once after the sound is completly loaded.

          See actionscript help for full details.
          • 2. Volume & Slider Position When Loaded
            Dyer55 Level 1
            Hi, Thanks for the reply.

            I tried to code it as you suggested but Its still opening up and playing the song with the volume all the way down. The volume slider (which I have coded as "dragger") is still opening up all the way to the left.

            I also tried coding it so that it loads by the click of a button and not through onEnterFrame

            I am wondering if maybe this has to do with the way the slider dragger is coded. Since it is coded to follow that pink line when its dragged up and down to change the volume.
            • 3. Re: Volume & Slider Position When Loaded
              S4Potential Level 1
              Once again, once an enterFrame event is triggered, it will be running ALL the time even when the dragging has stopped. Kill the enterFrame once it is not needed anymore:

              delete this.enterFrame
              delete mySlider.dragger.onEnterFrame

              Put some traces here and there to make sure that the load completion is actually detected and the enterFrames are deleted

              this.onEnterFrame = function():Void {
              trace("Enter this.EnterFrame");
              finished = mySound.getBytesLoaded(mcSoundHolder);
              total = mySound.getBytesTotal(mcSoundHolder);
              if (finished != total) { //if our song is not totaly downloaded
              mp3TextBox.songBox.text = "downloading.....";
              } else {
              //complete = 1; //only use this if not streaming
              mp3TextBox.songBox.text = "music by.....";
              trace("Completed sound loading detection in this.EnterFrame");
              }
              mySound.setVolume(_root.volume*2);
              }

              Do the same for the ;volume drag function.

              Traces are you friends. Use them everywhere you can and take them out once you know it is working well.

              Also,

              mySound.setVolume(_root.volume*2);

              Where did you declare _root.volume? if undefined or even 0 it won't work. 0*2=0;

              Why not simply do mySound.setVolume(50);
              • 4. Volume & Slider Position When Loaded
                Dyer55 Level 1
                Thanks again for your help.

                What you are saying makes a lot of sense. I'm going to remove both of them with the suggestions you have given me.

                About the _root.volume.
                It's declared in the slider.dragger function. I think what you have suggested is much better though ( the mySound.setVolume(50); ) and I will try that.

                Thanks for trying to help me, sometimes coding just gets the best of me. I am still learning and working it out. I am going to work on it again... cross fingers.