home *** CD-ROM | disk | FTP | other *** search
/ Canadian Forces: A World of Opportunities / CanadianForces-AWorldOfOpportunities-WinMac.bin / 02_JobsNavy_FR.swf / scripts / FScrollBarSymbol.as < prev    next >
Text File  |  2006-07-25  |  12KB  |  355 lines

  1. FScrollBarClass = function()
  2. {
  3.    if(this._height == 1)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this.width = this._height;
  11.    this._xscale = this._yscale = 100;
  12.    this.setScrollPosition(0);
  13.    this.tabEnabled = false;
  14.    if(this._targetInstanceName.length > 0)
  15.    {
  16.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  17.    }
  18.    this.tabChildren = false;
  19.    this.setSize(this.width);
  20. };
  21. FScrollBarClass.prototype = new FUIComponentClass();
  22. FScrollBarClass.prototype.setHorizontal = function(flag)
  23. {
  24.    if(this.horizontal && !flag)
  25.    {
  26.       this._xscale = 100;
  27.       this._rotation = 0;
  28.    }
  29.    else if(flag && !this.horizontal)
  30.    {
  31.       this._xscale = -100;
  32.       this._rotation = -90;
  33.    }
  34.    this.horizontal = flag;
  35. };
  36. FScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  37. {
  38.    if(!this.enable)
  39.    {
  40.       return undefined;
  41.    }
  42.    this.pageSize = pSize;
  43.    this.minPos = Math.max(mnPos,0);
  44.    this.maxPos = Math.max(mxPos,0);
  45.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  46.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  47.    if(this.maxPos - this.minPos <= 0)
  48.    {
  49.       this.scrollThumb_mc.removeMovieClip();
  50.       this.upArrow_mc.gotoAndStop(3);
  51.       this.downArrow_mc.gotoAndStop(3);
  52.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  53.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  54.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  55.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  56.       this.scrollTrack_mc.useHandCursor = false;
  57.    }
  58.    else
  59.    {
  60.       var _loc2_ = this.getScrollPosition();
  61.       this.upArrow_mc.gotoAndStop(1);
  62.       this.downArrow_mc.gotoAndStop(1);
  63.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  64.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  65.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  66.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  67.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  68.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  69.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  70.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  71.       this.scrollTrack_mc.useHandCursor = false;
  72.       this.attachMovie("ScrollThumb","scrollThumb_mc",3);
  73.       this.scrollThumb_mc._x = 0;
  74.       this.scrollThumb_mc._y = this.upArrow_mc._height;
  75.       this.scrollThumb_mc.onPress = this.startDragThumb;
  76.       this.scrollThumb_mc.controller = this;
  77.       this.scrollThumb_mc.onRelease = this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb;
  78.       this.scrollThumb_mc.useHandCursor = false;
  79.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * this.trackSize;
  80.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  81.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  82.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  83.       this.thumbHeight = Math.max(this.thumbHeight,6);
  84.       this.midHeight = this.thumbHeight - this.thumbTop_mc._height - this.thumbBot_mc._height;
  85.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  86.       this.thumbMid_mc._y = this.thumbTop_mc._height;
  87.       this.thumbBot_mc._y = this.thumbTop_mc._height + this.midHeight;
  88.       this.scrollTop = this.scrollThumb_mc._y;
  89.       this.trackHeight = this.trackSize - this.thumbHeight;
  90.       this.scrollBot = this.trackHeight + this.scrollTop;
  91.       _loc2_ = Math.min(_loc2_,this.maxPos);
  92.       this.setScrollPosition(Math.max(_loc2_,this.minPos));
  93.    }
  94. };
  95. FScrollBarClass.prototype.getScrollPosition = function()
  96. {
  97.    return this.scrollPosition;
  98. };
  99. FScrollBarClass.prototype.setScrollPosition = function(pos)
  100. {
  101.    if(this.scrollThumb_mc != undefined)
  102.    {
  103.       pos = Math.min(pos,this.maxPos);
  104.       pos = Math.max(pos,this.minPos);
  105.    }
  106.    this.scrollPosition = pos;
  107.    this.scrollThumb_mc._y = (pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos) + this.scrollTop;
  108.    this.executeCallBack();
  109. };
  110. FScrollBarClass.prototype.setLargeScroll = function(lScroll)
  111. {
  112.    this.largeScroll = lScroll;
  113. };
  114. FScrollBarClass.prototype.setSmallScroll = function(sScroll)
  115. {
  116.    this.smallScroll = sScroll;
  117. };
  118. FScrollBarClass.prototype.setEnabled = function(enabledFlag)
  119. {
  120.    var _loc3_ = this.enable;
  121.    if(enabledFlag && !_loc3_)
  122.    {
  123.       this.enable = enabledFlag;
  124.       if(this.textField != undefined)
  125.       {
  126.          this.setScrollTarget(this.textField);
  127.       }
  128.       else
  129.       {
  130.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  131.          this.setScrollPosition(this.cachedPos);
  132.       }
  133.       this.isAKludge = undefined;
  134.    }
  135.    else if(!enabledFlag && _loc3_)
  136.    {
  137.       this.textField.removeListener(this);
  138.       this.cachedPos = this.getScrollPosition();
  139.       this.cachedMinPos = this.minPos;
  140.       this.cachedMaxPos = this.maxPos;
  141.       if(this.isAKludge == undefined)
  142.       {
  143.          this.setScrollProperties(this.pageSize,0,0);
  144.       }
  145.       else
  146.       {
  147.          this.isAKludge = true;
  148.       }
  149.       this.enable = enabledFlag;
  150.    }
  151. };
  152. FScrollBarClass.prototype.setSize = function(hgt)
  153. {
  154.    if(this._height == 1)
  155.    {
  156.       return undefined;
  157.    }
  158.    this.width = hgt;
  159.    this.scrollTrack_mc._yscale = 100;
  160.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  161.    if(this.upArrow_mc == undefined)
  162.    {
  163.       this.attachMovie("UpArrow","upArrow_mc",1);
  164.       this.attachMovie("DownArrow","downArrow_mc",2);
  165.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  166.       this.upArrow_mc.useHandCursor = this.downArrow_mc.useHandCursor = false;
  167.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  168.       this.downArrow_mc._x = 0;
  169.    }
  170.    this.scrollTrack_mc.controller = this;
  171.    this.downArrow_mc._y = this.width - this.downArrow_mc._height;
  172.    this.trackSize = this.width - 2 * this.downArrow_mc._height;
  173.    this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  174. };
  175. FScrollBarClass.prototype.scrollIt = function(inc, mode)
  176. {
  177.    var _loc3_ = this.smallScroll;
  178.    if(inc != "one")
  179.    {
  180.       _loc3_ = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  181.    }
  182.    var _loc2_ = this.getScrollPosition() + mode * _loc3_;
  183.    if(_loc2_ > this.maxPos)
  184.    {
  185.       _loc2_ = this.maxPos;
  186.    }
  187.    else if(_loc2_ < this.minPos)
  188.    {
  189.       _loc2_ = this.minPos;
  190.    }
  191.    this.setScrollPosition(_loc2_);
  192. };
  193. FScrollBarClass.prototype.startDragThumb = function()
  194. {
  195.    this.lastY = this._ymouse;
  196.    this.onMouseMove = this.controller.dragThumb;
  197. };
  198. FScrollBarClass.prototype.dragThumb = function()
  199. {
  200.    this.scrollMove = this._ymouse - this.lastY;
  201.    this.scrollMove += this._y;
  202.    if(this.scrollMove < this.controller.scrollTop)
  203.    {
  204.       this.scrollMove = this.controller.scrollTop;
  205.    }
  206.    else if(this.scrollMove > this.controller.scrollBot)
  207.    {
  208.       this.scrollMove = this.controller.scrollBot;
  209.    }
  210.    this._y = this.scrollMove;
  211.    var _loc2_ = this.controller;
  212.    _loc2_.scrollPosition = Math.round((_loc2_.maxPos - _loc2_.minPos) * (this._y - _loc2_.scrollTop) / _loc2_.trackHeight) + _loc2_.minPos;
  213.    this.controller.isScrolling = true;
  214.    updateAfterEvent();
  215.    this.controller.executeCallBack();
  216. };
  217. FScrollBarClass.prototype.stopDragThumb = function()
  218. {
  219.    this.controller.isScrolling = false;
  220.    this.onMouseMove = null;
  221. };
  222. FScrollBarClass.prototype.startTrackScroller = function()
  223. {
  224.    this.controller.trackScroller();
  225.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  226. };
  227. FScrollBarClass.prototype.scrollInterval = function(inc, mode)
  228. {
  229.    clearInterval(this.scrolling);
  230.    if(inc == "page")
  231.    {
  232.       this.trackScroller();
  233.    }
  234.    else
  235.    {
  236.       this.scrollIt(inc,mode);
  237.    }
  238.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  239. };
  240. FScrollBarClass.prototype.trackScroller = function()
  241. {
  242.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  243.    {
  244.       this.scrollIt("page",1);
  245.    }
  246.    else if(this.scrollThumb_mc._y > this._ymouse)
  247.    {
  248.       this.scrollIt("page",-1);
  249.    }
  250. };
  251. FScrollBarClass.prototype.stopScrolling = function()
  252. {
  253.    this.controller.downArrow_mc.gotoAndStop(1);
  254.    this.controller.upArrow_mc.gotoAndStop(1);
  255.    clearInterval(this.controller.scrolling);
  256. };
  257. FScrollBarClass.prototype.startUpScroller = function()
  258. {
  259.    this.controller.upArrow_mc.gotoAndStop(2);
  260.    this.controller.scrollIt("one",-1);
  261.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  262. };
  263. FScrollBarClass.prototype.startDownScroller = function()
  264. {
  265.    this.controller.downArrow_mc.gotoAndStop(2);
  266.    this.controller.scrollIt("one",1);
  267.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  268. };
  269. FScrollBarClass.prototype.setScrollTarget = function(tF)
  270. {
  271.    if(tF == undefined)
  272.    {
  273.       this.textField.removeListener(this);
  274.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  275.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  276.       {
  277.          this.textField.unwatch("text");
  278.          this.textField.unwatch("htmltext");
  279.       }
  280.    }
  281.    this.textField = undefined;
  282.    if(!(tF instanceof TextField))
  283.    {
  284.       return undefined;
  285.    }
  286.    this.textField = tF;
  287.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  288.    this.onTextChanged();
  289.    this.onChanged = function()
  290.    {
  291.       this.onTextChanged();
  292.    };
  293.    this.onScroller = function()
  294.    {
  295.       if(!this.isScrolling)
  296.       {
  297.          if(!this.horizontal)
  298.          {
  299.             this.setScrollPosition(this.textField.scroll);
  300.          }
  301.          else
  302.          {
  303.             this.setScrollPosition(this.textField.hscroll);
  304.          }
  305.       }
  306.    };
  307.    this.textField.addListener(this);
  308.    this.textField.watch("text",this.callback);
  309.    this.textField.watch("htmlText",this.callback);
  310. };
  311. FScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  312. {
  313.    clearInterval(this.hScroller.synchScroll);
  314.    clearInterval(this.vScroller.synchScroll);
  315.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  316.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  317.    return newVal;
  318. };
  319. FScrollBarClass.prototype.onTextChanged = function()
  320. {
  321.    if(!this.enable || this.textField == undefined)
  322.    {
  323.       return undefined;
  324.    }
  325.    clearInterval(this.synchScroll);
  326.    if(this.horizontal)
  327.    {
  328.       var _loc3_ = this.textField.hscroll;
  329.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  330.       this.setScrollPosition(Math.min(_loc3_,this.textField.maxhscroll));
  331.    }
  332.    else
  333.    {
  334.       _loc3_ = this.textField.scroll;
  335.       var _loc2_ = this.textField.bottomScroll - this.textField.scroll;
  336.       this.setScrollProperties(_loc2_,1,this.textField.maxscroll);
  337.    }
  338. };
  339. FScrollBarClass.prototype.executeCallBack = function()
  340. {
  341.    if(this.textField == undefined)
  342.    {
  343.       super.executeCallBack();
  344.    }
  345.    else if(this.horizontal)
  346.    {
  347.       this.textField.hscroll = this.getScrollPosition();
  348.    }
  349.    else
  350.    {
  351.       this.textField.scroll = this.getScrollPosition();
  352.    }
  353. };
  354. Object.registerClass("FScrollBarSymbol",FScrollBarClass);
  355.