home *** CD-ROM | disk | FTP | other *** search
/ T-Online 6 / T-Online.iso / Animation / content / intro / intro.swf / scripts / __Packages / components / ui / scrollbar / ScrollBar.as
Encoding:
Text File  |  2005-10-20  |  9.8 KB  |  274 lines

  1. class components.ui.scrollbar.ScrollBar extends components.ui.GenericUIComponent
  2. {
  3.    var eventListener;
  4.    var event;
  5.    var instCounter;
  6.    var listeners;
  7.    var dataObj;
  8.    var scrollUpBtn;
  9.    var scrollDownBtn;
  10.    var upBtn;
  11.    var downBtn;
  12.    var scrollArea;
  13.    var scrollAreaBtn;
  14.    var drag;
  15.    var dragBtn;
  16.    var scrollbarBackground;
  17.    var IvID;
  18.    function ScrollBar()
  19.    {
  20.       super();
  21.       this.eventListener = new components.ui.scrollbar.listeners.ScrollBarListener();
  22.       this.eventListener.setHolder(this);
  23.       this.event = new application.core.EventDispatcher();
  24.       this.instCounter = 0;
  25.       this.listeners = [];
  26.       Object.registerClass("scrollUpBtn",components.ui.SimpleButtonLogic);
  27.       Object.registerClass("scrollDownBtn",components.ui.SimpleButtonLogic);
  28.       Object.registerClass("scrollAreaBtn",components.ui.scrollbar.core.ScrollByDragHeightLogic);
  29.       application.core.KeyControl.getInstance().addListener(this.eventListener);
  30.       application.core.FocusManager.getInstance().addListener(this.eventListener);
  31.    }
  32.    function onMouseWheel(delta)
  33.    {
  34.       if(application.core.KeyControl.getInstance().getEnabled() == true)
  35.       {
  36.          delta *= -1;
  37.          if(delta > 0)
  38.          {
  39.             this.dataObj.scrollBar.scrollDirection = 1;
  40.          }
  41.          else
  42.          {
  43.             this.dataObj.scrollBar.scrollDirection = -1;
  44.          }
  45.          var _loc2_ = 0;
  46.          while(_loc2_ < Math.abs(delta))
  47.          {
  48.             this.scrollOneStep();
  49.             _loc2_ = _loc2_ + 1;
  50.          }
  51.       }
  52.    }
  53.    function init()
  54.    {
  55.       var _loc2_ = this.attachMovie("scrollbarBackground","scrollbarBackground",this.instCounter++);
  56.       _loc2_._height = this.dataObj.scrollBar.height;
  57.       this.dataObj.scrollBar.width = _loc2_._width;
  58.    }
  59.    function build()
  60.    {
  61.       var _loc2_ = this.attachMovie("scrollUpBtn","scrollUpBtn",this.instCounter++);
  62.       _loc2_._width = this.dataObj.scrollBar.width;
  63.       _loc2_.moveTo(0,0);
  64.       this.dataObj.scrollBar.upBtnHeight = this.scrollUpBtn._height;
  65.       this.dataObj.scrollBar.upBtnWidth = this.dataObj.scrollBar.width;
  66.       _loc2_ = this.attachMovie("scrollDownBtn","scrollDownBtn",this.instCounter++);
  67.       _loc2_._width = this.dataObj.scrollBar.width;
  68.       _loc2_.moveTo(0,this.dataObj.scrollBar.height - _loc2_._height);
  69.       this.dataObj.scrollBar.downBtnHeight = this.scrollDownBtn._height;
  70.       this.dataObj.scrollBar.downBtnWidth = this.dataObj.scrollBar.width;
  71.       _loc2_ = this.attachMovie("scrollAreaBtn","scrollAreaBtn",this.instCounter++);
  72.       _loc2_.moveTo(0,this.dataObj.scrollBar.upBtnHeight);
  73.       this.dataObj.scrollBar.scrollAreaHeight = this.scrollDownBtn._y - this.scrollUpBtn._height;
  74.       this.dataObj.scrollBar.scrollAreaWidth = this.dataObj.scrollBar.width;
  75.       _loc2_.setDataProvider(this.dataObj);
  76.       _loc2_.setSize();
  77.       if(this.dataObj.contentTyp == "TextField")
  78.       {
  79.          Object.registerClass("dragBtn",components.ui.scrollbar.core.LineDragLogic);
  80.       }
  81.       else
  82.       {
  83.          Object.registerClass("dragBtn",components.ui.scrollbar.core.PixelDragLogic);
  84.       }
  85.       _loc2_ = this.attachMovie("dragBtn","dragBtn",this.instCounter++);
  86.       _loc2_.moveTo(0,this.dataObj.scrollBar.upBtnHeight);
  87.       var _loc3_ = _loc2_.attachMovie("dragBtnTop","t",1);
  88.       _loc3_.gotoAndStop(1);
  89.       var _loc5_ = _loc2_.attachMovie("dragBtnCenter","c",2);
  90.       _loc5_.gotoAndStop(1);
  91.       _loc5_._y = _loc3_._height;
  92.       _loc3_ = _loc5_;
  93.       _loc5_ = _loc2_.attachMovie("dragBtnBottem","b",3);
  94.       _loc5_.gotoAndStop(1);
  95.       _loc5_._y = _loc3_._y + _loc3_._height;
  96.       _loc2_.setDataProvider(this.dataObj);
  97.       _loc2_.init();
  98.       _loc2_.setSize();
  99.       var _loc4_ = _loc2_.attachMovie("dragDeko","dragDeko",20);
  100.       _loc4_._x = (_loc2_._width - _loc4_._width) / 2;
  101.       _loc4_._y = (_loc2_._height - _loc4_._height) / 2;
  102.       this.upBtn = new components.ui.scrollbar.listeners.UpBtnListener();
  103.       this.upBtn.setHolder(this);
  104.       this.scrollUpBtn.addListener(this.upBtn);
  105.       this.downBtn = new components.ui.scrollbar.listeners.DownBtnListener();
  106.       this.downBtn.setHolder(this);
  107.       this.scrollDownBtn.addListener(this.downBtn);
  108.       this.scrollArea = new components.ui.scrollbar.listeners.ScrollAreaBtnListener();
  109.       this.scrollArea.setHolder(this);
  110.       this.scrollAreaBtn.addListener(this.scrollArea);
  111.       this.drag = new components.ui.scrollbar.listeners.DragBtnListener();
  112.       this.drag.setHolder(this);
  113.       this.dragBtn.addListener(this.drag);
  114.    }
  115.    function update()
  116.    {
  117.       var _loc2_ = this.scrollbarBackground;
  118.       _loc2_._height = this.dataObj.scrollBar.height;
  119.       _loc2_ = this.scrollDownBtn;
  120.       _loc2_.moveTo(0,this.dataObj.scrollBar.height - _loc2_._height);
  121.       this.dataObj.scrollBar.downBtnHeight = this.scrollDownBtn._height;
  122.       this.dataObj.scrollBar.downBtnWidth = this.dataObj.scrollBar.width;
  123.       _loc2_ = this.scrollAreaBtn;
  124.       this.dataObj.scrollBar.scrollAreaHeight = this.scrollDownBtn._y - this.scrollUpBtn._height;
  125.       this.dataObj.scrollBar.scrollAreaWidth = this.dataObj.scrollBar.width;
  126.       _loc2_.setDataProvider(this.dataObj);
  127.       _loc2_.setSize();
  128.       _loc2_ = this.dragBtn;
  129.       _loc2_.moveTo(0,this.dataObj.scrollBar.upBtnHeight);
  130.       var _loc3_ = _loc2_.t;
  131.       _loc3_.gotoAndStop(1);
  132.       var _loc4_ = _loc2_.c;
  133.       _loc4_.gotoAndStop(1);
  134.       _loc4_._y = _loc3_._height;
  135.       _loc3_ = _loc4_;
  136.       _loc4_ = _loc2_.b;
  137.       _loc4_.gotoAndStop(1);
  138.       _loc4_._y = _loc3_._y + _loc3_._height;
  139.       _loc2_.init();
  140.       _loc2_.setSize();
  141.    }
  142.    function onScroll()
  143.    {
  144.    }
  145.    function onScrollonKeyEvent(dir)
  146.    {
  147.       this.dataObj.scrollBar.scrollDirection = dir;
  148.       this.scrollOneStep();
  149.    }
  150.    function addListener(holder)
  151.    {
  152.       this.event.addListener(holder);
  153.    }
  154.    function removeListener(holder)
  155.    {
  156.       this.event.removeListener(holder);
  157.    }
  158.    function scrollTo(pos)
  159.    {
  160.       if(pos > this.dataObj.content.contentToScroll)
  161.       {
  162.          pos = this.dataObj.content.contentToScroll;
  163.       }
  164.       this.dragBtn.setToPos(pos);
  165.       pos = this.dragBtn.getPos();
  166.       this.dataObj.scrollBar.dragPos = pos;
  167.       this.event.dispatchEvent("onScroll",this.dataObj.scrollBar.dragPos);
  168.    }
  169.    function startScroll()
  170.    {
  171.       var _loc2_ = this.dragBtn.getSize();
  172.       this.dragBtn.startDrag(false,0,this.scrollUpBtn._height,0,this.scrollDownBtn._y - _loc2_);
  173.       this.IvID = setInterval(this,"scroll",0);
  174.    }
  175.    function scroll()
  176.    {
  177.       var _loc2_ = this.dragBtn.getPos();
  178.       if(_loc2_ != this.dataObj.scrollBar.dragPos)
  179.       {
  180.          this.dataObj.scrollBar.dragPos = _loc2_;
  181.          this.event.dispatchEvent("onScroll",this.dataObj.scrollBar.dragPos);
  182.          this.onScroll();
  183.          updateAfterEvent();
  184.       }
  185.    }
  186.    function stopScroll()
  187.    {
  188.       clearInterval(this.IvID);
  189.       delete this.IvID;
  190.       this.dragBtn.stopDrag();
  191.    }
  192.    function startScrollOneStep(direction)
  193.    {
  194.       var _loc2_ = this.dataObj.scrollBar;
  195.       if((direction == -1 && _loc2_.dragPos >= 2) | (direction == 1 && _loc2_.dragPos <= this.dataObj.content.maxScroll - 1))
  196.       {
  197.          _loc2_.scrollDirection = direction;
  198.          _loc2_.dragPos = this.dragBtn.setPos(_loc2_.scrollDirection);
  199.          this.event.dispatchEvent("onScroll",_loc2_.dragPos);
  200.          this.onScroll();
  201.          updateAfterEvent();
  202.          this.IvID = setInterval(this,"waitForRelease",500);
  203.       }
  204.    }
  205.    function waitForRelease()
  206.    {
  207.       clearInterval(this.IvID);
  208.       delete this.IvID;
  209.       this.IvID = setInterval(this,"scrollOneStep",60);
  210.    }
  211.    function scrollOneStep()
  212.    {
  213.       var _loc2_ = this.dataObj.scrollBar;
  214.       if((_loc2_.scrollDirection == -1 && _loc2_.dragPos != 1) | (_loc2_.scrollDirection == 1 && _loc2_.dragPos != this.dataObj.content.maxScroll))
  215.       {
  216.          _loc2_.dragPos = this.dragBtn.setPos(_loc2_.scrollDirection);
  217.          this.event.dispatchEvent("onScroll",_loc2_.dragPos);
  218.          this.onScroll();
  219.          updateAfterEvent();
  220.       }
  221.       else
  222.       {
  223.          this.stopScrollOneStep();
  224.       }
  225.    }
  226.    function stopScrollOneStep()
  227.    {
  228.       clearInterval(this.IvID);
  229.       delete this.IvID;
  230.    }
  231.    function startScrollByDragHeight()
  232.    {
  233.       this.scrollAreaBtn.setFinalScrollPos();
  234.       this.IvID = setInterval(this,"ScrollByDragHeight",0);
  235.    }
  236.    function ScrollByDragHeight()
  237.    {
  238.       clearInterval(this.IvID);
  239.       delete this.IvID;
  240.       this.IvID = setInterval(this,"ScrollByDragHeight",150);
  241.       var _loc2_ = this.dataObj.scrollBar;
  242.       var _loc3_ = this.scrollAreaBtn.getNextPos();
  243.       if(_loc2_.scrollDirection == -1 && _loc3_ >= _loc2_.finalScrollPos || _loc2_.scrollDirection == 1 && _loc3_ <= _loc2_.finalScrollPos)
  244.       {
  245.          this.dragBtn._y = _loc3_;
  246.          this.scrollAreaBtn.update();
  247.          this.dataObj.scrollBar.dragPos = this.dragBtn.getPos();
  248.          this.event.dispatchEvent("onScroll",this.dataObj.scrollBar.dragPos);
  249.          this.onScroll();
  250.          updateAfterEvent();
  251.       }
  252.       else
  253.       {
  254.          this.dragBtn._y = _loc2_.finalScrollPos;
  255.          this.stopScrollByDragHeight();
  256.          this.scrollAreaBtn.update();
  257.          this.dataObj.scrollBar.dragPos = this.dragBtn.getPos();
  258.          this.event.dispatchEvent("onScroll",this.dataObj.scrollBar.dragPos);
  259.          this.onScroll();
  260.          updateAfterEvent();
  261.       }
  262.    }
  263.    function stopScrollByDragHeight()
  264.    {
  265.       clearInterval(this.IvID);
  266.       delete this.IvID;
  267.    }
  268.    function onUnload()
  269.    {
  270.       application.core.FocusManager.getInstance().removeListener(this.eventListener);
  271.       application.core.KeyControl.getInstance().removeListener(this.eventListener);
  272.    }
  273. }
  274.