Control sound volume with ActionScript

January 16, 2010

Actionscript 3.0 Tutorial

Click “Play” and then arrows to adjust sound volume:

Minimum Flash Designer version: 5.0.23.2

Download source project here (826 kb)

  1. Launch Flash Designer and set movie dimensions 180 x 180 (or any desired).
  2. Change frame delay to “Stop”.
  3. Extract “sound1.mp3″ file from here and import the sound with Movie > Import Sound
  4. Choose “Frame” > “ActionScript” and paste the code:
    mySnd = new Sound();
    mySnd.attachSound("sound1.mp3");
    volume = 100;
    
  5. Choose “Insert” > “Navigation” and insert play, stop, up and down buttons.
  6. Extract “equalizer.sfd” file from t1052.zip. Choose “Movie” > “Insert Flash Designer Clip” and insert “equalizer.sfd” file. Choose “Item” > “Placement Properties” and check “ActionScript Target”
  7. Define “OnClick” action for Up arrow:
    volume = volume + 10;
    if(volume>100) volume = 100;
    mySnd.setVolume(volume);
    
  8. Define “OnClick” action for Down arrow:
    volume = volume - 10;
    if(volume<0) volume = 0;
    mySnd.setVolume(volume);
    
  9. Define “OnClick” action for Play arrow:
    mySnd.start(0,100);
    equalizer.gotoAndPlay("Frame 2");
    
  10. Define “OnClick” action for Stop button:
    mySnd.stop();
    equalizer.gotoAndPlay("Frame 1");
    

Hit F9 for preview.

, , , , ,

Subscribe

Subscribe to our e-mail newsletter to receive updates.

4 Responses to “Control sound volume with ActionScript”

  1. Tanmoy Mistri Says:

    Thanks.Very helpful tutorial for my lab assignment.

  2. skin care Says:

    One thing I would like to comment on is that fat reduction plan fast may be possible by the perfect diet and exercise. People’s size not merely affects appearance, but also the complete quality of life. Self-esteem, despression symptoms, health risks, and physical ability are influenced in extra weight. It is possible to do everything right whilst still having a gain. Should this happen, a condition may be the perpetrator. While a lot food and never enough exercise are usually at fault, common medical conditions and trusted prescriptions could greatly increase size. I am grateful for your post here.

Trackbacks/Pingbacks

  1. Control sound volume with ActionScript | Flash tutorial | Flash … | Drakz Free Online Service - January 16, 2010

    [...] the original: Control sound volume with ActionScript | Flash tutorial | Flash … Share and [...]

  2. Control sound volume with ActionScript | Flash tutorial | Flash … | Drakz Free Online Service - January 16, 2010

    [...] link: Control sound volume with ActionScript | Flash tutorial | Flash … Share and [...]

Leave a Reply