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

  1. class Music
  2. {
  3.    var mySound;
  4.    var volume;
  5.    var currentTrack;
  6.    var inCrossfade;
  7.    var state;
  8.    var changeSongs;
  9.    var maxVolume;
  10.    var targetVolume;
  11.    var volumeSpeed;
  12.    function Music()
  13.    {
  14.       this.mySound = new Sound();
  15.       this.volume = 100;
  16.       this.currentTrack = "";
  17.       this.inCrossfade = false;
  18.       this.state = false;
  19.       this.changeSongs = true;
  20.       this.maxVolume = 100;
  21.    }
  22.    function SetMaxVolume(vol)
  23.    {
  24.       this.maxVolume = vol;
  25.    }
  26.    function SetTrack(setMusic)
  27.    {
  28.       if(setMusic == this.currentTrack)
  29.       {
  30.          this.changeSongs = false;
  31.       }
  32.       else
  33.       {
  34.          this.changeSongs = true;
  35.          this.currentTrack = setMusic;
  36.       }
  37.    }
  38.    function Play()
  39.    {
  40.       this.mySound.stop();
  41.       this.mySound.attachSound(this.currentTrack);
  42.       this.volume = this.maxVolume;
  43.       this.mySound.setVolume(this.volume);
  44.       this.mySound.start(0,2000);
  45.       this.state = true;
  46.    }
  47.    function Stop()
  48.    {
  49.       this.mySound.stop();
  50.       this.state = false;
  51.    }
  52.    function PlayWithCrossFade(secondDuration)
  53.    {
  54.       if(this.changeSongs == true)
  55.       {
  56.          if(this.state == true)
  57.          {
  58.             this.inCrossfade = true;
  59.             this.targetVolume = 0;
  60.             var _loc2_ = secondDuration * 50;
  61.             this.volumeSpeed = (this.targetVolume - this.volume) / (_loc2_ / 2);
  62.          }
  63.          else
  64.          {
  65.             this.mySound.stop();
  66.             this.mySound.attachSound(this.currentTrack);
  67.             this.mySound.start(0,2000);
  68.             this.state = true;
  69.             this.inCrossfade = false;
  70.             this.targetVolume = this.maxVolume;
  71.             this.volume = 0;
  72.             this.mySound.setVolume(0);
  73.             _loc2_ = secondDuration * 50;
  74.             this.volumeSpeed = (this.targetVolume - this.volume) / _loc2_;
  75.          }
  76.       }
  77.    }
  78.    function RunPlayer()
  79.    {
  80.       if(this.targetVolume != this.volume)
  81.       {
  82.          var _loc2_ = undefined;
  83.          _loc2_ = this.volume + this.volumeSpeed;
  84.          if(this.volumeSpeed < 0 && _loc2_ < 0)
  85.          {
  86.             _loc2_ = 0;
  87.          }
  88.          else if(this.volumeSpeed > 0 && _loc2_ > this.targetVolume)
  89.          {
  90.             _loc2_ = this.targetVolume;
  91.          }
  92.          this.volume = _loc2_;
  93.          this.mySound.setVolume(_loc2_);
  94.       }
  95.       if(this.inCrossfade == true)
  96.       {
  97.          if(this.volume <= 0)
  98.          {
  99.             this.volumeSpeed *= -1;
  100.             this.inCrossfade = false;
  101.             this.targetVolume = this.maxVolume;
  102.             this.mySound.stop();
  103.             this.mySound.attachSound(this.currentTrack);
  104.             this.mySound.setVolume(0);
  105.             this.mySound.start(0,2000);
  106.             this.state = true;
  107.          }
  108.       }
  109.    }
  110. }
  111.