home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Acao / bubble_tanks_2.swf / scripts / __Packages / SoundPlayer.as < prev    next >
Encoding:
Text File  |  2008-09-02  |  6.6 KB  |  209 lines

  1. class SoundPlayer
  2. {
  3.    var channelsAvailable;
  4.    var channel1;
  5.    var channel2;
  6.    var channel3;
  7.    var channel4;
  8.    var channel5;
  9.    var channel6;
  10.    var channel7;
  11.    var externalSoundVolume;
  12.    var start;
  13.    function SoundPlayer()
  14.    {
  15.       this.channelsAvailable = new Array(true,true,true,true,true,true,true);
  16.       this.channel1 = new Sound(_root.soundOneClip);
  17.       this.channel2 = new Sound(_root.soundTwoClip);
  18.       this.channel3 = new Sound(_root.soundThreeClip);
  19.       this.channel4 = new Sound(_root.soundFourClip);
  20.       this.channel5 = new Sound(_root.soundFiveClip);
  21.       this.channel6 = new Sound(_root.soundSixClip);
  22.       this.channel7 = new Sound(_root.soundSevenClip);
  23.       this.externalSoundVolume = 100;
  24.    }
  25.    function CleanSounds(intIndex)
  26.    {
  27.       this.channelsAvailable[intIndex] = true;
  28.    }
  29.    function PlaySound(linkIdentifier)
  30.    {
  31.       if(_global.soundOn == true)
  32.       {
  33.          var thisRef = this;
  34.          if(this.channelsAvailable[0] == true)
  35.          {
  36.             this.channelsAvailable[0] = false;
  37.             delete this.channel1;
  38.             this.channel1 = new Sound(_root.soundOneClip);
  39.             this.channel1.attachSound(linkIdentifier);
  40.             this.channel1.setVolume(100);
  41.             this.channel1.start(0,0);
  42.             this.channel1.onSoundComplete = function()
  43.             {
  44.                thisRef.CleanSounds(0);
  45.             };
  46.          }
  47.          else if(this.channelsAvailable[1] == true)
  48.          {
  49.             this.channelsAvailable[1] = false;
  50.             delete this.channel2;
  51.             this.channel2 = new Sound(_root.soundTwoClip);
  52.             this.channel2.attachSound(linkIdentifier);
  53.             this.channel2.setVolume(100);
  54.             this.channel2.start(0,0);
  55.             this.channel2.onSoundComplete = function()
  56.             {
  57.                thisRef.CleanSounds(1);
  58.             };
  59.          }
  60.          else if(this.channelsAvailable[4] == true)
  61.          {
  62.             this.channelsAvailable[4] = false;
  63.             delete this.channel5;
  64.             this.channel5 = new Sound(_root.soundFiveClip);
  65.             this.channel5.attachSound(linkIdentifier);
  66.             this.channel5.setVolume(100);
  67.             this.channel5.start(0,0);
  68.             this.channel5.onSoundComplete = function()
  69.             {
  70.                thisRef.CleanSounds(4);
  71.             };
  72.          }
  73.          else if(this.channelsAvailable[5] == true)
  74.          {
  75.             this.channelsAvailable[5] = false;
  76.             delete this.channel6;
  77.             this.channel6 = new Sound(_root.soundSixClip);
  78.             this.channel6.attachSound(linkIdentifier);
  79.             this.channel6.setVolume(100);
  80.             this.channel6.start(0,0);
  81.             this.channel6.onSoundComplete = function()
  82.             {
  83.                thisRef.CleanSounds(5);
  84.             };
  85.          }
  86.          else
  87.          {
  88.             this.channelsAvailable[0] = false;
  89.             delete this.channel1;
  90.             this.channel1 = new Sound(_root.soundOneClip);
  91.             this.channel1.attachSound(linkIdentifier);
  92.             this.channel1.setVolume(100);
  93.             this.channel1.start(0,0);
  94.             this.channel1.onSoundComplete = function()
  95.             {
  96.                thisRef.CleanSounds(0);
  97.             };
  98.          }
  99.       }
  100.    }
  101.    function PlayBubbleSound(linkIdentifier)
  102.    {
  103.       if(_global.soundOn == true)
  104.       {
  105.          var thisRef = this;
  106.          if(this.channelsAvailable[2] == true)
  107.          {
  108.             this.channelsAvailable[2] = false;
  109.             delete this.channel3;
  110.             this.channel3 = new Sound(_root.soundThreeClip);
  111.             this.channel3.attachSound(linkIdentifier);
  112.             this.channel3.setVolume(100);
  113.             this.channel3.start(0,0);
  114.             this.channel3.onSoundComplete = function()
  115.             {
  116.                thisRef.CleanSounds(2);
  117.             };
  118.          }
  119.          else if(this.channelsAvailable[3] == true)
  120.          {
  121.             this.channelsAvailable[3] = false;
  122.             delete this.channel4;
  123.             this.channel4 = new Sound(_root.soundFourClip);
  124.             this.channel4.attachSound(linkIdentifier);
  125.             this.channel4.setVolume(80);
  126.             this.channel4.start(0,0);
  127.             this.channel4.onSoundComplete = function()
  128.             {
  129.                thisRef.CleanSounds(3);
  130.             };
  131.          }
  132.          else if(this.channelsAvailable[6] == true)
  133.          {
  134.             this.channelsAvailable[6] = false;
  135.             delete this.channel7;
  136.             this.channel7 = new Sound(_root.soundSevenClip);
  137.             this.channel7.attachSound(linkIdentifier);
  138.             this.channel7.setVolume(60);
  139.             this.channel7.start(0,0);
  140.             this.channel7.onSoundComplete = function()
  141.             {
  142.                thisRef.CleanSounds(6);
  143.             };
  144.          }
  145.       }
  146.    }
  147.    function PlayExternalSound(urlPath)
  148.    {
  149.       var thisRef = this;
  150.       if(this.channelsAvailable[0] == true)
  151.       {
  152.          this.channelsAvailable[0] = false;
  153.          delete this.channel1;
  154.          this.channel1 = new Sound();
  155.          this.channel1.loadSound(urlPath,false);
  156.          this.channel1.setVolume(this.externalSoundVolume);
  157.          this.channel1.onLoad = function(loadedOK)
  158.          {
  159.             if(loadedOK)
  160.             {
  161.                this.start();
  162.             }
  163.          };
  164.          this.channel1.onSoundComplete = function()
  165.          {
  166.             thisRef.CleanSounds(0);
  167.          };
  168.       }
  169.       else if(this.channelsAvailable[1] == true)
  170.       {
  171.          this.channelsAvailable[1] = false;
  172.          delete this.channel2;
  173.          this.channel2 = new Sound();
  174.          this.channel2.loadSound(urlPath,false);
  175.          this.channel2.setVolume(this.externalSoundVolume);
  176.          this.channel2.onLoad = function(loadedOK)
  177.          {
  178.             if(loadedOK)
  179.             {
  180.                this.start();
  181.             }
  182.          };
  183.          this.channel2.onSoundComplete = function()
  184.          {
  185.             thisRef.CleanSounds(1);
  186.          };
  187.       }
  188.       else
  189.       {
  190.          this.channelsAvailable[0] = false;
  191.          delete this.channel1;
  192.          this.channel1 = new Sound();
  193.          this.channel1.loadSound(urlPath,false);
  194.          this.channel1.setVolume(this.externalSoundVolume);
  195.          this.channel1.onLoad = function(loadedOK)
  196.          {
  197.             if(loadedOK)
  198.             {
  199.                this.start();
  200.             }
  201.          };
  202.          this.channel1.onSoundComplete = function()
  203.          {
  204.             thisRef.CleanSounds(0);
  205.          };
  206.       }
  207.    }
  208. }
  209.