home *** CD-ROM | disk | FTP | other *** search
/ i·claim - visualizing argument / ICLAIM.ISO / pc / glossary.swf / scripts / __Packages / mx / controls / streamingmedia / PlayBar.as < prev    next >
Encoding:
Text File  |  2005-02-24  |  6.2 KB  |  214 lines

  1. class mx.controls.streamingmedia.PlayBar extends MovieClip
  2. {
  3.    var _controller;
  4.    var _thumb;
  5.    var _hilite;
  6.    var _timeTextField;
  7.    var _statusTextField;
  8.    var onEnterFrame;
  9.    var _darkenText;
  10.    var _textPulseTime;
  11.    var _tray;
  12.    static var TEXT_ALPHA_DARK = 100;
  13.    static var TEXT_ALPHA_LIGHT = 50;
  14.    static var PULSE_DURATION = 1400;
  15.    static var ACTIVE_PULSE_PORTION = 0.4;
  16.    static var STREAMING_ID = "streaming";
  17.    static var PAUSED_ID = "paused";
  18.    function PlayBar()
  19.    {
  20.       super();
  21.       this.init();
  22.    }
  23.    function init()
  24.    {
  25.       this._controller = this._parent;
  26.       this.setCompletionPercentage(this._controller.playPercent);
  27.       this.setTime(this._controller.playTime);
  28.       this.draw();
  29.    }
  30.    function isVertical()
  31.    {
  32.       return !this._controller.horizontal;
  33.    }
  34.    function getCompletionPercentage()
  35.    {
  36.       var _loc2_ = undefined;
  37.       if(this.isVertical())
  38.       {
  39.          _loc2_ = this.yToPercent(this._thumb._y);
  40.       }
  41.       else
  42.       {
  43.          _loc2_ = this.xToPercent(this._thumb._x);
  44.       }
  45.       return _loc2_;
  46.    }
  47.    function setCompletionPercentage(aPercentage)
  48.    {
  49.       aPercentage = Math.floor(aPercentage);
  50.       if(aPercentage < 1)
  51.       {
  52.          aPercentage = 1;
  53.       }
  54.       else if(aPercentage > 100)
  55.       {
  56.          aPercentage = 100;
  57.       }
  58.       if(this.isVertical())
  59.       {
  60.          var _loc3_ = this.percentToY(aPercentage);
  61.          this._thumb._y = this.getHeight() - _loc3_ - 9;
  62.       }
  63.       else
  64.       {
  65.          var _loc4_ = this.percentToX(aPercentage);
  66.          this._thumb._x = _loc4_;
  67.       }
  68.       this.updateHiliteToMatchThumb();
  69.    }
  70.    function updateHiliteToMatchThumb()
  71.    {
  72.       if(this.isVertical())
  73.       {
  74.          this._hilite._height = this.getHeight() - this._thumb._y - 6;
  75.          this._hilite._y = this.getHeight() - this._hilite._height - 1;
  76.       }
  77.       else
  78.       {
  79.          this._hilite._width = this._thumb._x + 4;
  80.       }
  81.    }
  82.    function setTime(aTime)
  83.    {
  84.       var _loc7_ = Math.floor(aTime / 3600);
  85.       var _loc3_ = aTime % 3600;
  86.       var _loc6_ = Math.floor(_loc3_ / 60);
  87.       _loc3_ %= 60;
  88.       var _loc5_ = Math.floor(_loc3_);
  89.       _loc3_ %= 1;
  90.       var _loc2_ = Math.round(_loc3_ * 1000);
  91.       var _loc4_ = _loc7_ + ":" + (_loc6_ >= 10 ? "" : "0") + _loc6_ + ":" + (_loc5_ >= 10 ? "" : "0") + _loc5_ + ".";
  92.       if(_loc2_ < 10)
  93.       {
  94.          _loc4_ += "00" + String(_loc2_);
  95.       }
  96.       else if(_loc2_ < 100)
  97.       {
  98.          _loc4_ += "0" + String(_loc2_);
  99.       }
  100.       else
  101.       {
  102.          _loc4_ += String(_loc2_);
  103.       }
  104.       this._timeTextField.text = _loc4_;
  105.    }
  106.    function setIsPlaying(isPlaying)
  107.    {
  108.       if(isPlaying)
  109.       {
  110.          this._statusTextField.text = this._controller.getLocalizedString(mx.controls.streamingmedia.PlayBar.STREAMING_ID);
  111.          delete this.onEnterFrame;
  112.          this.setDarkText();
  113.       }
  114.       else
  115.       {
  116.          this._statusTextField.text = this._controller.getLocalizedString(mx.controls.streamingmedia.PlayBar.PAUSED_ID);
  117.          this._darkenText = false;
  118.          this._textPulseTime = getTimer();
  119.          this.onEnterFrame = this.pulseText;
  120.       }
  121.    }
  122.    function getController()
  123.    {
  124.       return this._controller;
  125.    }
  126.    function draw()
  127.    {
  128.       var _loc2_ = this.getCompletionPercentage();
  129.       if(this.isVertical())
  130.       {
  131.          this._x = (this._controller.width - this.getWidth()) / 2;
  132.          this._y = 8;
  133.          this._tray.setHeight(this.getHeight());
  134.          this._statusTextField._y = this.getHeight() - 4;
  135.       }
  136.       else
  137.       {
  138.          this._x = 8;
  139.          this._tray.setWidth(this.getWidth());
  140.          this._timeTextField._x = this.getWidth() - this._timeTextField._width - 3;
  141.       }
  142.       this.setIsPlaying(this._controller.isPlaying());
  143.       this.setCompletionPercentage(_loc2_);
  144.    }
  145.    function getWidth()
  146.    {
  147.       var _loc2_ = !this.isVertical() ? this._controller.width - 16 : 20;
  148.       return _loc2_;
  149.    }
  150.    function getHeight()
  151.    {
  152.       var _loc2_ = !this.isVertical() ? 20 : this._controller.height - 90;
  153.       return _loc2_;
  154.    }
  155.    function xToPercent(x)
  156.    {
  157.       var _loc2_ = 100 * ((x + 3) / (this.getWidth() - 3));
  158.       return _loc2_;
  159.    }
  160.    function percentToX(percent)
  161.    {
  162.       var _loc2_ = (this.getWidth() - 3) * (percent / 100) - 3;
  163.       return _loc2_;
  164.    }
  165.    function yToPercent(y)
  166.    {
  167.       var _loc2_ = 100 * ((this.getHeight() - 3 - y) / this.getHeight());
  168.       return _loc2_;
  169.    }
  170.    function percentToY(percent)
  171.    {
  172.       var _loc2_ = (this.getHeight() - 3) * (percent / 100) - 3;
  173.       return _loc2_;
  174.    }
  175.    function pulseText()
  176.    {
  177.       var _loc2_ = getTimer() - this._textPulseTime;
  178.       var _loc5_ = Math.min(1,_loc2_ / mx.controls.streamingmedia.PlayBar.PULSE_DURATION);
  179.       var _loc7_ = mx.controls.streamingmedia.PlayBar.PULSE_DURATION * mx.controls.streamingmedia.PlayBar.ACTIVE_PULSE_PORTION;
  180.       var _loc6_ = Math.min(1,_loc2_ / _loc7_);
  181.       var _loc4_ = _loc6_ * (mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK - mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT);
  182.       var _loc3_ = !this._darkenText ? mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK - _loc4_ : mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT + _loc4_;
  183.       this._statusTextField._alpha = _loc3_;
  184.       this._timeTextField._alpha = _loc3_;
  185.       if(_loc5_ >= 1)
  186.       {
  187.          this._darkenText = !this._darkenText;
  188.          this._textPulseTime = getTimer();
  189.       }
  190.    }
  191.    function setDarkText()
  192.    {
  193.       this._statusTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK;
  194.       this._timeTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_DARK;
  195.    }
  196.    function setLightText()
  197.    {
  198.       this._statusTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT;
  199.       this._timeTextField._alpha = mx.controls.streamingmedia.PlayBar.TEXT_ALPHA_LIGHT;
  200.    }
  201.    function get enabled()
  202.    {
  203.       return this._thumb.enabled;
  204.    }
  205.    function set enabled(is)
  206.    {
  207.       this._thumb.enabled = is;
  208.    }
  209.    function isScrubbing()
  210.    {
  211.       return this._thumb.isScrubbing();
  212.    }
  213. }
  214.