Advertisement
nutter666

Sound Manager

Sep 13th, 2017
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.media.SoundChannel;
  3.     import flash.media.Sound;
  4.     import flash.events.Event;
  5.    
  6.     public class SoundManager {
  7.        
  8.         var mainClass; // this would be whatever class instantiates your game.
  9.        
  10.         [Embed(source = "../Sounds/GunshotSelect.mp3")]
  11.         protected static const gunShotClass:Class;
  12.         var gunShotSound:Sound = new gunShotClass; 
  13.  
  14.         /*[Embed(source = "../Music/MusicLoop.mp3")]
  15.         protected static const mainMusicClass:Class;
  16.         var mainMusicLoop:Sound = new mainMusicClass;  
  17.         */
  18.  
  19.  
  20.         var musicChannel:SoundChannel; // not used for sound effects, ignore it for now
  21.  
  22.         public function SoundManager(mClass) {
  23.             // constructor code
  24.         mainClass = mClass
  25.         }
  26.  
  27.         /*
  28.         function startMusic(){
  29.         if(musicChannel != null){
  30.         musicChannel.stop();
  31.         }
  32.         musicChannel = mainMusicLoop.play();
  33.         musicChannel.addEventListener(Event.SOUND_COMPLETE,loopMusic)
  34.         }
  35.        
  36.         function loopMusic(e:Event){
  37.         startMusic();
  38.         }
  39.         */
  40.  
  41.         function playSound(soundName:String){
  42.         switch(soundName){
  43.        
  44.         case "gunshot":
  45.         gunShotSound.play();
  46.         break;
  47.  
  48.  
  49.         }
  50.        
  51.        
  52.         }
  53.  
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement