home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / lightsprites.swf / scripts / __Packages / SoundPlayer.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  4.9 KB  |  171 lines

  1. class SoundPlayer
  2. {
  3.    var channelsAvailable;
  4.    var channel1;
  5.    var channel2;
  6.    var voiceChannel;
  7.    var hitChannel;
  8.    var externalSoundVolume;
  9.    var start;
  10.    function SoundPlayer()
  11.    {
  12.       this.channelsAvailable = new Array(true,true,true,true);
  13.       this.channel1 = new Sound();
  14.       this.channel2 = new Sound();
  15.       this.voiceChannel = new Sound();
  16.       this.hitChannel = new Sound();
  17.       this.externalSoundVolume = 100;
  18.    }
  19.    function CleanSounds(intIndex)
  20.    {
  21.       this.channelsAvailable[intIndex] = true;
  22.    }
  23.    function PlaySound(linkIdentifier)
  24.    {
  25.       if(_global.soundOn == true)
  26.       {
  27.          var thisRef = this;
  28.          if(this.channelsAvailable[0] == true)
  29.          {
  30.             this.channelsAvailable[0] = false;
  31.             delete this.channel1;
  32.             this.channel1 = new Sound();
  33.             this.channel1.attachSound(linkIdentifier);
  34.             this.channel1.setVolume(100);
  35.             this.channel1.start(0,0);
  36.             this.channel1.onSoundComplete = function()
  37.             {
  38.                thisRef.CleanSounds(0);
  39.             };
  40.          }
  41.          else if(this.channelsAvailable[1] == true)
  42.          {
  43.             this.channelsAvailable[1] = false;
  44.             delete this.channel2;
  45.             this.channel2 = new Sound();
  46.             this.channel2.attachSound(linkIdentifier);
  47.             this.channel2.setVolume(100);
  48.             this.channel2.start(0,0);
  49.             this.channel2.onSoundComplete = function()
  50.             {
  51.                thisRef.CleanSounds(1);
  52.             };
  53.          }
  54.          else
  55.          {
  56.             this.channelsAvailable[0] = false;
  57.             delete this.channel1;
  58.             this.channel1 = new Sound();
  59.             this.channel1.attachSound(linkIdentifier);
  60.             this.channel1.setVolume(100);
  61.             this.channel1.start(0,0);
  62.             this.channel1.onSoundComplete = function()
  63.             {
  64.                thisRef.CleanSounds(0);
  65.             };
  66.          }
  67.       }
  68.    }
  69.    function PlayHitSound(linkIdentifier)
  70.    {
  71.       if(_global.soundOn == true)
  72.       {
  73.          var thisRef = this;
  74.          if(this.channelsAvailable[2] == true)
  75.          {
  76.             this.channelsAvailable[2] = false;
  77.             delete this.hitChannel;
  78.             this.hitChannel = new Sound();
  79.             this.hitChannel.attachSound(linkIdentifier);
  80.             this.hitChannel.setVolume(100);
  81.             this.hitChannel.start(0,0);
  82.             this.hitChannel.onSoundComplete = function()
  83.             {
  84.                thisRef.CleanSounds(2);
  85.             };
  86.          }
  87.       }
  88.    }
  89.    function PlayVoiceSound(linkIdentifier)
  90.    {
  91.       if(_global.soundOn == true)
  92.       {
  93.          var thisRef = this;
  94.          if(this.channelsAvailable[3] == true)
  95.          {
  96.             this.channelsAvailable[3] = false;
  97.             delete this.voiceChannel;
  98.             this.voiceChannel = new Sound();
  99.             this.voiceChannel.attachSound(linkIdentifier);
  100.             this.voiceChannel.setVolume(100);
  101.             this.voiceChannel.start(0,0);
  102.             this.voiceChannel.onSoundComplete = function()
  103.             {
  104.                thisRef.CleanSounds(3);
  105.             };
  106.          }
  107.       }
  108.    }
  109.    function PlayExternalSound(urlPath)
  110.    {
  111.       var thisRef = this;
  112.       if(this.channelsAvailable[0] == true)
  113.       {
  114.          this.channelsAvailable[0] = false;
  115.          delete this.channel1;
  116.          this.channel1 = new Sound();
  117.          this.channel1.loadSound(urlPath,false);
  118.          this.channel1.setVolume(this.externalSoundVolume);
  119.          this.channel1.onLoad = function(loadedOK)
  120.          {
  121.             if(loadedOK)
  122.             {
  123.                this.start();
  124.             }
  125.          };
  126.          this.channel1.onSoundComplete = function()
  127.          {
  128.             thisRef.CleanSounds(0);
  129.          };
  130.       }
  131.       else if(this.channelsAvailable[1] == true)
  132.       {
  133.          this.channelsAvailable[1] = false;
  134.          delete this.channel2;
  135.          this.channel2 = new Sound();
  136.          this.channel2.loadSound(urlPath,false);
  137.          this.channel2.setVolume(this.externalSoundVolume);
  138.          this.channel2.onLoad = function(loadedOK)
  139.          {
  140.             if(loadedOK)
  141.             {
  142.                this.start();
  143.             }
  144.          };
  145.          this.channel2.onSoundComplete = function()
  146.          {
  147.             thisRef.CleanSounds(1);
  148.          };
  149.       }
  150.       else
  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.    }
  170. }
  171.