home *** CD-ROM | disk | FTP | other *** search
/ Neil's C++ Stuff / 2016-02-neilstuff-weebly.iso / apps / audioPlayer2.swf / scripts / __Packages / Volume.as < prev   
Encoding:
Text File  |  2016-02-05  |  3.5 KB  |  116 lines

  1. class Volume extends MovieClip
  2. {
  3.    var control_mc;
  4.    var button_mc;
  5.    var icon_mc;
  6.    var _settingVolume;
  7.    var _initialMaskPos;
  8.    var realWidth;
  9.    var background_mc;
  10.    var broadcastMessage;
  11.    var _clearID;
  12.    var _rtl = false;
  13.    function Volume()
  14.    {
  15.       super();
  16.       AsBroadcaster.initialize(this);
  17.       this.control_mc._alpha = 0;
  18.       this.button_mc._visible = false;
  19.       this.icon_mc._alpha = 100;
  20.       this._settingVolume = false;
  21.       this._initialMaskPos = this.control_mc.mask_mc._x;
  22.       this.realWidth = this.background_mc._width;
  23.       this.button_mc.onPress = mx.utils.Delegate.create(this,function()
  24.       {
  25.          this._settingVolume = true;
  26.          this._moveVolumeBar();
  27.       }
  28.       );
  29.       this.button_mc.onMouseMove = mx.utils.Delegate.create(this,function()
  30.       {
  31.          if(this._settingVolume)
  32.          {
  33.             this._moveVolumeBar();
  34.             this.broadcastMessage("onSetVolume",this._getValue(),false);
  35.          }
  36.       }
  37.       );
  38.       this.button_mc.onRelease = this.button_mc.onReleaseOutside = mx.utils.Delegate.create(this,function()
  39.       {
  40.          this._settingVolume = false;
  41.          this._moveVolumeBar();
  42.          this.broadcastMessage("onSetVolume",this._getValue(),true);
  43.       }
  44.       );
  45.    }
  46.    function update(volume)
  47.    {
  48.       if(!this._settingVolume)
  49.       {
  50.          this.control_mc.mask_mc._x = this._initialMaskPos + Math.round(this.control_mc.track_mc._width * volume / 100);
  51.       }
  52.    }
  53.    function _moveVolumeBar()
  54.    {
  55.       if(this.control_mc.track_mc._xmouse > this.control_mc.track_mc._width)
  56.       {
  57.          this.control_mc.mask_mc._x = this._initialMaskPos + this.control_mc.track_mc._width;
  58.       }
  59.       else if(this.control_mc.track_mc._xmouse < 0)
  60.       {
  61.          this.control_mc.mask_mc._x = this._initialMaskPos;
  62.       }
  63.       else
  64.       {
  65.          this.control_mc.mask_mc._x = this._initialMaskPos + this.control_mc.track_mc._xmouse;
  66.       }
  67.    }
  68.    function _getValue()
  69.    {
  70.       return Math.round((this.control_mc.mask_mc._x - this._initialMaskPos) / this.control_mc.track_mc._width * 100);
  71.    }
  72.    function toggleControl(toggle, immediate)
  73.    {
  74.       clearInterval(this._clearID);
  75.       if(toggle)
  76.       {
  77.          this._clearID = setInterval(this,"_animate",41,100,0,!this._rtl ? 6 : 11);
  78.       }
  79.       else
  80.       {
  81.          this._clearID = setInterval(this,"_animate",41,0,100,!this._rtl ? 16 : 21);
  82.       }
  83.    }
  84.    function _animate(targetControl, targetIcon, targetIconX)
  85.    {
  86.       var _loc2_ = targetControl - this.control_mc._alpha;
  87.       var _loc5_ = targetIcon - this.icon_mc._alpha;
  88.       var _loc4_ = targetIconX - this.icon_mc._x;
  89.       var _loc3_ = 0.3;
  90.       _loc2_ *= _loc3_;
  91.       _loc5_ *= _loc3_;
  92.       _loc4_ *= _loc3_;
  93.       if(Math.abs(_loc2_) < 1)
  94.       {
  95.          this.control_mc._alpha = targetControl;
  96.          this.icon_mc._alpha = targetIcon;
  97.          this.icon_mc._x = targetIconX;
  98.          this.button_mc._visible = this.control_mc._alpha == 100;
  99.          clearInterval(this._clearID);
  100.          return undefined;
  101.       }
  102.       this.control_mc._alpha += _loc2_;
  103.       this.icon_mc._alpha += _loc5_;
  104.       this.icon_mc._x += _loc4_;
  105.    }
  106.    function flip()
  107.    {
  108.       this._rtl = true;
  109.       this.background_mc._rotation = 180;
  110.       this.background_mc._y += this.background_mc._height;
  111.       this.background_mc._x += this.background_mc._width;
  112.       this.control_mc._x += 5;
  113.       this.icon_mc._x += 5;
  114.    }
  115. }
  116.