Posted By

Ktoso on 02/26/09


Tagged

action script flash slider sound 3 volume


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

themill
trevorhartman
Pingpongbal
ClayVillage
jafar
tspitzr
dubogii
Josueriv


AS3 Volume Slider


 / Published in: ActionScript 3
 

URL: http://www.project13.pl

Simple yet effective way to create a horizontal slider to controll the volume of your sound channel

  1. var maxMove:Number =50;
  2.  
  3. var bounds:Rectangle = new Rectangle(this.volumeSlider.x, this.volumeSlider.y, -maxMove, 0);
  4. var scrolling:Boolean = false;
  5.  
  6. function startScroll (e:Event):void {
  7. scrolling = true;
  8. this.volumeSlider.startDrag (false,bounds);
  9. }
  10.  
  11. function stopScroll (e:Event):void {
  12. scrolling = false;
  13. this.volumeSlider.stopDrag ();
  14. }
  15.  
  16. function enterHandler (e:Event):void {
  17. if (scrolling == true) {
  18. MovieClip(this.root).setVolume(1-((bounds.x-this.volumeSlider.x)/maxMove));
  19. }
  20. }
  21.  
  22. function setVolume(vol:Number){
  23. var mod:SoundTransform = new SoundTransform();
  24. mod.volume = vol;
  25. mp3Channel.soundTransform = mod; //apply to yout mp3Channel
  26. }
  27.  
  28. addEventListener (Event.ENTER_FRAME, enterHandler);
  29.  
  30. this.volumeSlider.addEventListener (MouseEvent.MOUSE_DOWN, startScroll);
  31. stage.addEventListener (MouseEvent.MOUSE_UP, stopScroll);

Report this snippet  

You need to login to post a comment.