Advertisement
nutter666

Sound Manager (Fixed)

Sep 13th, 2017
676
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:Main;
  9.        
  10.         var battleLoop:Sound = new BattleLoop1();
  11.  
  12.         var blockDamage:Sound = new BlockDamage();
  13.         var blockCrumble:Sound = new BlockCrumble();
  14.         var blockRebound:Sound = new BlockRebound();
  15.         var ballBounce:Sound = new BallBounce();
  16.        
  17.         var explosion1:Sound = new Explosion1();
  18.         var explosion2:Sound = new Explosion2();
  19.         var explosion3:Sound = new Explosion3();
  20.         var explosion4:Sound = new Explosion4();
  21.         var explosion5:Sound = new Explosion5();
  22.        
  23.         var laser1:Sound = new Laser1();
  24.         var laser2:Sound = new Laser2();
  25.        
  26.         var powerup1:Sound = new Powerup1();
  27.         var powerup2:Sound = new Powerup2();
  28.         var powerup3:Sound = new Powerup3();
  29.         var powerup4:Sound = new Powerup4();
  30.         var powerup5:Sound = new Powerup5();
  31.         var powerup6:Sound = new Powerup6();
  32.                
  33.         var musicChannel:SoundChannel;
  34.         var victoryChannel:SoundChannel;
  35.  
  36.         public function SoundManager(mClass) {
  37.             // constructor code
  38.         mainClass = mClass
  39.         }
  40.        
  41.         function startBattleMusic(){
  42.         if(musicChannel != null){
  43.         musicChannel.stop();
  44.         }
  45.         musicChannel = battleLoop.play();
  46.         musicChannel.addEventListener(Event.SOUND_COMPLETE,loopBattleMusic)
  47.         }
  48.        
  49.         function loopBattleMusic(e:Event){
  50.         startBattleMusic();
  51.         }
  52.        
  53.         function finishBattle(){
  54.         musicChannel.stop();
  55.         victoryChannel = victoryJingle.play();
  56.         victoryChannel.addEventListener(Event.SOUND_COMPLETE,finishJingle)
  57.         }
  58.        
  59.         function finishJingle(e:Event){
  60.         trace("jingle finished")
  61.         }
  62.  
  63.         function playSound(soundName:String){
  64.         if(soundName == "blockDamage"){
  65.         blockDamage.play();
  66.         }
  67.         else if(soundName == "blockCrumble"){
  68.         blockCrumble.play();
  69.         }
  70.         else if(soundName == "metalCollide"){
  71.         blockRebound.play();
  72.         }
  73.         else if(soundName == "laserShot1"){
  74.         laser1.play();
  75.         }
  76.         else if(soundName == "laserShot2"){
  77.         laser2.play();
  78.         }
  79.         else if(soundName == "paddleBounce"){
  80.         ballBounce.play();
  81.         }
  82.         else if(soundName == "ballBounce"){
  83.         ballBounce.play();
  84.         }
  85.         else if(soundName == "powerup1"){
  86.         powerup1.play();
  87.         }
  88.         else if(soundName == "powerup2"){
  89.         powerup2.play();
  90.         }
  91.         else if(soundName == "powerup3"){
  92.         powerup3.play();
  93.         }
  94.         else if(soundName == "powerup4"){
  95.         powerup4.play();
  96.         }
  97.         else if(soundName == "powerup5"){
  98.         powerup5.play();
  99.         }
  100.         else if(soundName == "powerup6"){
  101.         powerup6.play();
  102.         }
  103.         else if(soundName == "ballExplode"){
  104.         explosion5.play();
  105.         }
  106.         else if(soundName == "explosion1"){
  107.         explosion1.play();
  108.         }
  109.         else if(soundName == "explosion2"){
  110.         explosion2.play();
  111.         }
  112.         else if(soundName == "explosion3"){
  113.         explosion3.play();
  114.         }
  115.         else if(soundName == "explosion4"){
  116.         explosion4.play();
  117.         }
  118.         else if(soundName == "explosion5"){
  119.         explosion5.play();
  120.         }
  121.        
  122.         }
  123.  
  124.     }
  125.    
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement