A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] How to control sound/volume of Movie Clip?

  1. #1
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29

    [F8] How to control sound/volume of Movie Clip?

    Been searching through the forum posts looking for an answer to this. If I embed a video (with sound) in a MovieClip, say "mcMovie," how would I go about controlling the volume of mcMovie specifically? Since there is no sound or volume propety for the MovieClip class, I'm assuming I would have to declare a sound object from the Media class and then attach it to mcMovie? Can anyone give me some general hints as to how I would go about this. Thank you.

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    I'll have to look into it a little, but generally you aren't worried about the sound in the embedded video, you need to control the sound of the Flash piece. You are correct, you will create a sound object, and setVolume to adjust it. I'll verify and get you some code.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    Thank you. I wasn't sure whether to post this in Newbies or Actionscript (which I'm starting to learn now), but having a piece of example code will be nice.

    Rob

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813

    ..here you go...

    I tried to attached a copy of the code below, but because I was using music for my audio, it was large than allowed for upload. In any case, the code below is exactly what I used. I place the audio file directly on the timeline and the code below adjusted the volume of the stage which affects everything with sound.

    Code:
    var stepsListener = new Object(); 
    var myAudio:Sound = new Sound();
    
    stepsListener.change = function() { 
     trace("Value was changed.");
     adjustVolume(); 
    }; 
    stepperMain.addEventListener("change", stepsListener); 
    
    adjustVolume = function(){
    	myAudio.setVolume(stepperMain.value);
    }
    Hope this works for you.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    Junior Member
    Join Date
    May 2007
    Location
    FL
    Posts
    29
    What I have right now is a movie clip (mcMovie) whose alpha fades up or down when pressing mcButton. mcMovie is an embedded video clip which has sound. So I'm wondering how I would fade the sound along with the alpha. Here is the code I'm using now:

    PHP Code:
    mcMovie._alpha 0;
    mcText._visible false;
    mcButton.onPress = function() {
        
    alphaUp();
    };
    mcButton.onRelease = function() {
        
    setTimeout(alphaDown200);
    };
    function 
    alphaUp() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha<100 this._alpha += 10 delete this.onEnterFrame;
            
    mcText._visible true;
        };
    }
    function 
    alphaDown() {
        
    mcMovie.onEnterFrame = function() {
            
    this._alpha>this._alpha -= 20 delete this.onEnterFrame;
            
    mcText._visible false;
        };


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center