Volume control AS3


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import flash.media.SoundMixer;
  2. import flash.media.SoundTransform;
  3.  
  4.  
  5. //All sound channels
  6. SoundMixer.soundTransform = new SoundTransform(.5);
  7.  
  8.  
  9.  
  10. //Without a sound channel:
  11. var sTransform:SoundTransform = new SoundTransform();
  12. sTransform.volume = volumeLevel;
  13. musicSoundChannel.soundTransform = sTransform;
  14.  
  15.  
  16. //With a sound channel:
  17. protected static var musicSoundChannel:SoundChannel;
  18. ...
  19. var urlRequest:URLRequest = new URLRequest(url);
  20. if (musicSoundChannel != null){
  21. musicSoundChannel.stop();
  22. }
  23. musicSound = new Sound();
  24. musicSound.load(urlRequest);
  25. if (musicSound != null){
  26. musicSoundChannel = musicSound.play();
  27. }
  28.  
  29. var sTransform:SoundTransform = new SoundTransform();
  30. sTransform.volume = volumeLevel; //Volume level is a Number between 0 and 1
  31. musicSoundChannel.soundTransform = sTransform;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.