home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / jig.swf / scripts / __Packages / SoundChannel.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  2.8 KB  |  130 lines

  1. class SoundChannel
  2. {
  3.    var channelid;
  4.    var sound;
  5.    var index;
  6.    var volume;
  7.    var mode;
  8.    var playlist;
  9.    var sync = false;
  10.    var threshold = 500;
  11.    function SoundChannel(sync)
  12.    {
  13.       if(typeof _root.soundchannels != "object")
  14.       {
  15.          _root.soundchannels = new Array();
  16.          _root.createEmptyMovieClip("soundchannelclips",4095);
  17.       }
  18.       this.channelid = _root.soundchannels.length;
  19.       _root.soundchannels.push(this);
  20.       var _loc3_ = _root.soundchannelclips.createEmptyMovieClip("channel" + this.channelid,this.channelid);
  21.       this.sound = new Sound(_loc3_);
  22.       this.index = 0;
  23.       this.volume = 100;
  24.       this.mode = 0;
  25.       if(sync != undefined)
  26.       {
  27.          this.sync = sync;
  28.       }
  29.       if(this.sync)
  30.       {
  31.          this.sound.onSoundComplete = this.NextAll;
  32.       }
  33.    }
  34.    function SetPlaylist(arr)
  35.    {
  36.       this.playlist = arr;
  37.       var _loc3_ = 0;
  38.       var _loc2_ = 0;
  39.       while(_loc2_ < this.playlist.length)
  40.       {
  41.          _loc3_ += this.playlist[_loc2_].length;
  42.          _loc2_ = _loc2_ + 1;
  43.       }
  44.    }
  45.    function GetCurrentTrack()
  46.    {
  47.       return this.playlist[this.index];
  48.    }
  49.    function FarQueue(s)
  50.    {
  51.       this.playlist.push(s);
  52.    }
  53.    function NearQueue(s)
  54.    {
  55.       this.playlist.splice(this.index + 1,0,s);
  56.    }
  57.    function SetVolume(v)
  58.    {
  59.       if(v != undefined)
  60.       {
  61.          this.volume = v;
  62.       }
  63.       v = Math.floor(this.volume * this.GetCurrentTrack().volume / 100);
  64.       this.sound.setVolume(v);
  65.    }
  66.    function AddVolume(v)
  67.    {
  68.       var _loc2_ = this.volume + v;
  69.       if(_loc2_ < 0)
  70.       {
  71.          _loc2_ = 0;
  72.       }
  73.       if(_loc2_ > 100)
  74.       {
  75.          _loc2_ = 100;
  76.       }
  77.       this.SetVolume(_loc2_);
  78.    }
  79.    function Pause()
  80.    {
  81.       this.sound.stop();
  82.    }
  83.    function Stop()
  84.    {
  85.       this.Pause();
  86.       this.index = 0;
  87.       this.mode = 0;
  88.    }
  89.    function Play()
  90.    {
  91.       this.mode = 1;
  92.       var _loc2_ = this.GetCurrentTrack();
  93.       if(!_loc2_)
  94.       {
  95.          return undefined;
  96.       }
  97.       this.sound.attachSound(_loc2_.file);
  98.       this.SetVolume();
  99.       this.sound.start();
  100.    }
  101.    function Next()
  102.    {
  103.       if(this.mode == 0)
  104.       {
  105.          return undefined;
  106.       }
  107.       var _loc2_ = this.GetCurrentTrack();
  108.       if(!_loc2_.Next())
  109.       {
  110.          return undefined;
  111.       }
  112.       this.index = this.index + 1;
  113.       if(this.index >= this.playlist.length)
  114.       {
  115.          this.index = 0;
  116.       }
  117.       this.Play();
  118.    }
  119.    function NextAll()
  120.    {
  121.       var _loc2_ = 0;
  122.       while(_loc2_ < _root.soundchannels.length)
  123.       {
  124.          _root.soundchannels[_loc2_].Next();
  125.          var _loc3_ = _root.soundchannels[_loc2_];
  126.          _loc2_ = _loc2_ + 1;
  127.       }
  128.    }
  129. }
  130.