home *** CD-ROM | disk | FTP | other *** search
/ Canadian Forces: Prepare for Takeoff as a Pilot / CF_FS_Air.iso.iso / pc / data / swf / flashpaper / 102_fr.swf / scripts / MScrollBarSymbol.as < prev    next >
Text File  |  2004-09-01  |  16KB  |  489 lines

  1. MScrollBarClass = function()
  2. {
  3.    if(this._height == 4)
  4.    {
  5.       return undefined;
  6.    }
  7.    this.init();
  8.    this.minPos = this.maxPos = this.pageSize = this.largeScroll = 0;
  9.    this.smallScroll = 1;
  10.    this.buttonHeight = 16;
  11.    this.scrollThumbSymbol = "mScrollThumb";
  12.    this.upArrowSymbol = "mUpArrow";
  13.    this.downArrowSymbol = "mDownArrow";
  14.    if(this.style == "Small")
  15.    {
  16.       this.buttonHeight = 12;
  17.       this.scrollThumbSymbol = "mSmallScrollThumb";
  18.       this.upArrowSymbol = "mSmallUpArrow";
  19.       this.downArrowSymbol = "mSmallDownArrow";
  20.    }
  21.    this.width = !this.horizontal ? this._height : this._width;
  22.    this._xscale = this._yscale = 100;
  23.    this.setScrollPosition(0);
  24.    this.tabEnabled = false;
  25.    if(this._targetInstanceName.length > 0)
  26.    {
  27.       this.setScrollTarget(this._parent[this._targetInstanceName]);
  28.    }
  29.    this.tabChildren = false;
  30.    this.setSize(this.width);
  31. };
  32. MScrollBarClass.prototype = new MUIComponentClass();
  33. MScrollBarClass.prototype.setHorizontal = function(flag)
  34. {
  35.    if(this.horizontal && !flag)
  36.    {
  37.       this._xscale = 100;
  38.       this._rotation = 0;
  39.    }
  40.    else if(flag && !this.horizontal)
  41.    {
  42.       this._xscale = -100;
  43.       this._rotation = -90;
  44.    }
  45.    this.horizontal = flag;
  46. };
  47. MScrollBarClass.prototype.setScrollProperties = function(pSize, mnPos, mxPos)
  48. {
  49.    if(!this.enable)
  50.    {
  51.       return undefined;
  52.    }
  53.    this.pageSize = pSize;
  54.    this.minPos = Math.max(mnPos,0);
  55.    this.maxPos = Math.max(mxPos,0);
  56.    this.scrollPosition = Math.max(this.minPos,this.scrollPosition);
  57.    this.scrollPosition = Math.min(this.maxPos,this.scrollPosition);
  58.    if(this.maxPos - this.minPos <= 0)
  59.    {
  60.       this.scrollThumb_mc.removeMovieClip();
  61.       if(this.style == "Small")
  62.       {
  63.          this.scrollTrack_mc.gotoAndStop("small_disabled");
  64.       }
  65.       else
  66.       {
  67.          this.scrollTrack_mc.gotoAndStop("disabled");
  68.       }
  69.       this.upArrow_mc.gotoAndStop("disabled");
  70.       this.downArrow_mc.gotoAndStop("disabled");
  71.       this.downArrow_mc.onPress = this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = null;
  72.       this.upArrow_mc.onPress = this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = null;
  73.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onRelease = null;
  74.       this.scrollTrack_mc.onDragOut = this.scrollTrack_mc.onRollOut = null;
  75.       this.scrollTrack_mc.useHandCursor = false;
  76.    }
  77.    else
  78.    {
  79.       var shadowOffset = 3;
  80.       var tmp = this.getScrollPosition();
  81.       if(this.style == "Small")
  82.       {
  83.          this.scrollTrack_mc.gotoAndStop("small_enabled");
  84.       }
  85.       else
  86.       {
  87.          this.scrollTrack_mc.gotoAndStop("enabled");
  88.       }
  89.       this.upArrow_mc.gotoAndStop("up");
  90.       this.downArrow_mc.gotoAndStop("up");
  91.       this.upArrow_mc.onPress = this.upArrow_mc.onDragOver = this.startUpScroller;
  92.       this.upArrow_mc.onRelease = this.upArrow_mc.onDragOut = this.stopScrolling;
  93.       this.upArrow_mc.onRollOver = this.rolloverScroller;
  94.       this.upArrow_mc.onRollOut = this.upArrow_mc.onReleaseOutside = this.rolloutScroller;
  95.       this.downArrow_mc.onPress = this.downArrow_mc.onDragOver = this.startDownScroller;
  96.       this.downArrow_mc.onRelease = this.downArrow_mc.onDragOut = this.stopScrolling;
  97.       this.downArrow_mc.onRollOver = this.rolloverScroller;
  98.       this.downArrow_mc.onRollOut = this.downArrow_mc.onReleaseOutside = this.rolloutScroller;
  99.       this.scrollTrack_mc.onPress = this.scrollTrack_mc.onDragOver = this.startTrackScroller;
  100.       this.scrollTrack_mc.onRelease = this.stopScrolling;
  101.       this.scrollTrack_mc.onDragOut = this.stopScrolling;
  102.       this.scrollTrack_mc.onRollOut = this.stopScrolling;
  103.       this.scrollTrack_mc.useHandCursor = false;
  104.       this.attachMovie(this.scrollThumbSymbol,"scrollThumb_mc",3);
  105.       this.scrollThumb_mc._x = 0;
  106.       this.scrollThumb_mc._y = this.buttonHeight - shadowOffset;
  107.       this.scrollThumb_mc.onPress = this.startDragThumb;
  108.       this.scrollThumb_mc.controller = this;
  109.       this.scrollThumb_mc.onRelease = this.scrollThumb_mc.onReleaseOutside = this.stopDragThumb;
  110.       this.scrollThumb_mc.onRollOver = this.rolloverThumb;
  111.       this.scrollThumb_mc.onRollOut = this.rolloutThumb;
  112.       this.scrollThumb_mc.onDragOut = this.dragoutThumb;
  113.       this.scrollThumb_mc.useHandCursor = false;
  114.       var trackSize = this.width - this.buttonHeight * 2;
  115.       this.thumbHeight = this.pageSize / (this.maxPos - this.minPos + this.pageSize) * trackSize;
  116.       this.thumbMid_mc = this.scrollThumb_mc.mc_sliderMid;
  117.       this.thumbTop_mc = this.scrollThumb_mc.mc_sliderTop;
  118.       this.thumbBot_mc = this.scrollThumb_mc.mc_sliderBot;
  119.       this.thumbGrips = this.scrollThumb_mc.grips;
  120.       this.thumbHeight = Math.max(this.thumbHeight,26);
  121.       this.midHeight = this.thumbHeight - 10;
  122.       this.thumbMid_mc._yScale = this.midHeight * 100 / this.thumbMid_mc._height;
  123.       this.thumbMid_mc._y = 5 - shadowOffset;
  124.       this.thumbGrips._y = Math.floor(this.thumbHeight / 2 - this.thumbGrips._height / 2 - shadowOffset / 2);
  125.       if(this.thumbHeight < 20)
  126.       {
  127.          this.thumbGrips._visible = false;
  128.       }
  129.       this.thumbBot_mc._y = 5 + this.midHeight - shadowOffset;
  130.       this.scrollTop = this.scrollThumb_mc._y + shadowOffset;
  131.       this.trackHeight = trackSize - this.thumbHeight + shadowOffset;
  132.       this.scrollBot = this.trackHeight + this.scrollTop;
  133.       tmp = Math.min(tmp,this.maxPos);
  134.       this.setScrollPosition(Math.max(tmp,this.minPos));
  135.    }
  136. };
  137. MScrollBarClass.prototype.getScrollPosition = function()
  138. {
  139.    return this.scrollPosition;
  140. };
  141. MScrollBarClass.prototype.setScrollPosition = function(pos)
  142. {
  143.    this.scrollPosition = pos;
  144.    if(this.scrollThumb_mc != undefined)
  145.    {
  146.       pos = Math.min(pos,this.maxPos);
  147.       pos = Math.max(pos,this.minPos);
  148.    }
  149.    this.scrollThumb_mc._y = Math.round((pos - this.minPos) * this.trackHeight / (this.maxPos - this.minPos)) + this.scrollTop;
  150.    this.executeCallBack();
  151. };
  152. MScrollBarClass.prototype.setLargeScroll = function(lScroll)
  153. {
  154.    this.largeScroll = lScroll;
  155. };
  156. MScrollBarClass.prototype.setSmallScroll = function(sScroll)
  157. {
  158.    this.smallScroll = sScroll;
  159. };
  160. MScrollBarClass.prototype.setEnabled = function(enabledFlag)
  161. {
  162.    var wasEnabled = this.enable;
  163.    if(enabledFlag && !wasEnabled)
  164.    {
  165.       this.enable = enabledFlag;
  166.       if(this.textField != undefined)
  167.       {
  168.          this.setScrollTarget(this.textField);
  169.       }
  170.       else
  171.       {
  172.          this.setScrollProperties(this.pageSize,this.cachedMinPos,this.cachedMaxPos);
  173.          this.setScrollPosition(this.cachedPos);
  174.       }
  175.       this.clickFilter = undefined;
  176.    }
  177.    else if(!enabledFlag && wasEnabled)
  178.    {
  179.       this.textField.removeListener(this);
  180.       this.cachedPos = this.getScrollPosition();
  181.       this.cachedMinPos = this.minPos;
  182.       this.cachedMaxPos = this.maxPos;
  183.       if(this.clickFilter == undefined)
  184.       {
  185.          this.setScrollProperties(this.pageSize,0,0);
  186.       }
  187.       else
  188.       {
  189.          this.clickFilter = true;
  190.       }
  191.       this.enable = enabledFlag;
  192.    }
  193. };
  194. MScrollBarClass.prototype.getStyle = function()
  195. {
  196.    return this.style;
  197. };
  198. MScrollBarClass.prototype.setStyle = function(style)
  199. {
  200.    this.style = style.toLowerCase() != "small" ? "Normal" : "Small";
  201.    this.buttonHeight = 16;
  202.    this.scrollThumbSymbol = "mScrollThumb";
  203.    this.upArrowSymbol = "mUpArrow";
  204.    this.downArrowSymbol = "mDownArrow";
  205.    if(this.style == "Small")
  206.    {
  207.       this.buttonHeight = 12;
  208.       this.scrollThumbSymbol = "mSmallScrollThumb";
  209.       this.upArrowSymbol = "mSmallUpArrow";
  210.       this.downArrowSymbol = "mSmallDownArrow";
  211.    }
  212.    this.upArrow_mc.removeMovieClip();
  213.    this.downArrow_mc.removeMovieClip();
  214.    this.setSize(this.width - 1);
  215. };
  216. MScrollBarClass.prototype.setSize = function(hgt)
  217. {
  218.    if(this._height == 1)
  219.    {
  220.       return undefined;
  221.    }
  222.    this.width = hgt + 1;
  223.    this.scrollTrack_mc._yscale = 100;
  224.    this.scrollTrack_mc._yscale = 100 * this.width / this.scrollTrack_mc._height;
  225.    if(this.upArrow_mc == undefined)
  226.    {
  227.       this.attachMovie(this.upArrowSymbol,"upArrow_mc",1);
  228.       this.attachMovie(this.downArrowSymbol,"downArrow_mc",2);
  229.       this.downArrow_mc.controller = this.upArrow_mc.controller = this;
  230.       this.upArrow_mc.useHandCursor = this.downArrow_mc.useHandCursor = false;
  231.       this.upArrow_mc._x = this.upArrow_mc._y = 0;
  232.       this.downArrow_mc._x = 0;
  233.    }
  234.    this.scrollTrack_mc.controller = this;
  235.    this.downArrow_mc._y = this.width - this.buttonHeight;
  236.    if(this.textField != undefined)
  237.    {
  238.       this.onTextChanged();
  239.    }
  240.    else
  241.    {
  242.       this.setScrollProperties(this.pageSize,this.minPos,this.maxPos);
  243.    }
  244.    this.scrollTrack_mc.topShad._yscale = 100;
  245.    this.scrollTrack_mc.topShad._xscale = 100;
  246.    this.scrollTrack_mc.topShad._y = this.scrollTrack_mc._y + 8;
  247.    this.scrollTrack_mc.botShad._yscale = 100;
  248.    this.scrollTrack_mc.botShad._xscale = 100;
  249.    this.scrollTrack_mc.botShad._y = this.downArrow_mc._y - 8;
  250. };
  251. MScrollBarClass.prototype.scrollIt = function(inc, mode)
  252. {
  253.    var delt = this.smallScroll;
  254.    if(inc != "one")
  255.    {
  256.       delt = this.largeScroll != 0 ? this.largeScroll : this.pageSize;
  257.    }
  258.    var newPos = this.getScrollPosition() + mode * delt;
  259.    if(newPos > this.maxPos)
  260.    {
  261.       newPos = this.maxPos;
  262.    }
  263.    else if(newPos < this.minPos)
  264.    {
  265.       newPos = this.minPos;
  266.    }
  267.    this.setScrollPosition(newPos);
  268. };
  269. MScrollBarClass.prototype.startDragThumb = function()
  270. {
  271.    this.mc_sliderTop.gotoAndStop("down");
  272.    this.mc_sliderBot.gotoAndStop("down");
  273.    this.mc_sliderMid.gotoAndStop("down");
  274.    this.grips.gotoAndStop("down");
  275.    this.lastY = this._ymouse;
  276.    this.onMouseMove = this.controller.dragThumb;
  277. };
  278. MScrollBarClass.prototype.dragThumb = function()
  279. {
  280.    this.scrollMove = this._ymouse - this.lastY;
  281.    this.scrollMove += this._y;
  282.    if(this.scrollMove < this.controller.scrollTop)
  283.    {
  284.       this.scrollMove = this.controller.scrollTop;
  285.    }
  286.    else if(this.scrollMove > this.controller.scrollBot)
  287.    {
  288.       this.scrollMove = this.controller.scrollBot;
  289.    }
  290.    this._y = this.scrollMove;
  291.    var c = this.controller;
  292.    c.scrollPosition = Math.round((c.maxPos - c.minPos) * (this._y - c.scrollTop) / c.trackHeight) + c.minPos;
  293.    this.controller.isScrolling = true;
  294.    updateAfterEvent();
  295.    this.controller.executeCallBack();
  296. };
  297. MScrollBarClass.prototype.stopDragThumb = function()
  298. {
  299.    var upState = "up";
  300.    if(this.mouseOver)
  301.    {
  302.       upState = "over";
  303.    }
  304.    this.mc_sliderTop.gotoAndStop(upState);
  305.    this.mc_sliderBot.gotoAndStop(upState);
  306.    this.mc_sliderMid.gotoAndStop(upState);
  307.    this.grips.gotoAndStop(upState);
  308.    this.controller.isScrolling = false;
  309.    this.onMouseMove = null;
  310. };
  311. MScrollBarClass.prototype.rolloverThumb = function()
  312. {
  313.    this.mouseOver = true;
  314.    this.mc_sliderTop.gotoAndStop("over");
  315.    this.mc_sliderBot.gotoAndStop("over");
  316.    this.mc_sliderMid.gotoAndStop("over");
  317.    this.grips.gotoAndStop("over");
  318. };
  319. MScrollBarClass.prototype.rolloutThumb = function()
  320. {
  321.    this.mouseOver = false;
  322.    this.mc_sliderTop.gotoAndStop("up");
  323.    this.mc_sliderBot.gotoAndStop("up");
  324.    this.mc_sliderMid.gotoAndStop("up");
  325.    this.grips.gotoAndStop("up");
  326. };
  327. MScrollBarClass.prototype.dragoutThumb = function()
  328. {
  329.    this.mouseOver = false;
  330. };
  331. MScrollBarClass.prototype.startTrackScroller = function()
  332. {
  333.    this.controller.trackScroller();
  334.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"page",-1);
  335. };
  336. MScrollBarClass.prototype.scrollInterval = function(inc, mode)
  337. {
  338.    clearInterval(this.scrolling);
  339.    if(inc == "page")
  340.    {
  341.       this.trackScroller();
  342.    }
  343.    else
  344.    {
  345.       this.scrollIt(inc,mode);
  346.    }
  347.    this.scrolling = setInterval(this,"scrollInterval",35,inc,mode);
  348. };
  349. MScrollBarClass.prototype.trackScroller = function()
  350. {
  351.    if(this.scrollThumb_mc._y + this.thumbHeight < this._ymouse)
  352.    {
  353.       this.scrollIt("page",1);
  354.    }
  355.    else if(this.scrollThumb_mc._y > this._ymouse)
  356.    {
  357.       this.scrollIt("page",-1);
  358.    }
  359. };
  360. MScrollBarClass.prototype.stopScrolling = function()
  361. {
  362.    if(this.controller.downArrow_mc.mouseOver)
  363.    {
  364.       this.controller.downArrow_mc.gotoAndStop("over");
  365.    }
  366.    else
  367.    {
  368.       this.controller.downArrow_mc.gotoAndStop("up");
  369.    }
  370.    if(this.controller.upArrow_mc.mouseOver)
  371.    {
  372.       this.controller.upArrow_mc.gotoAndStop("over");
  373.    }
  374.    else
  375.    {
  376.       this.controller.upArrow_mc.gotoAndStop("up");
  377.    }
  378.    clearInterval(this.controller.scrolling);
  379. };
  380. MScrollBarClass.prototype.startUpScroller = function()
  381. {
  382.    this.controller.upArrow_mc.gotoAndStop("down");
  383.    this.controller.scrollIt("one",-1);
  384.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",-1);
  385. };
  386. MScrollBarClass.prototype.startDownScroller = function()
  387. {
  388.    this.controller.downArrow_mc.gotoAndStop("down");
  389.    this.controller.scrollIt("one",1);
  390.    this.controller.scrolling = setInterval(this.controller,"scrollInterval",500,"one",1);
  391. };
  392. MScrollBarClass.prototype.rolloverScroller = function()
  393. {
  394.    this.mouseOver = true;
  395.    this.gotoAndStop("over");
  396. };
  397. MScrollBarClass.prototype.rolloutScroller = function()
  398. {
  399.    this.mouseOver = false;
  400.    this.gotoAndStop("up");
  401. };
  402. MScrollBarClass.prototype.setScrollTarget = function(tF)
  403. {
  404.    if(tF == undefined)
  405.    {
  406.       this.textField.removeListener(this);
  407.       delete this.textField[!this.horizontal ? "vScroller" : "hScroller"];
  408.       if(this.textField.hScroller != undefined && this.textField.vScroller != undefined)
  409.       {
  410.          this.textField.unwatch("text");
  411.          this.textField.unwatch("htmltext");
  412.       }
  413.    }
  414.    this.textField = undefined;
  415.    if(!(tF instanceof TextField))
  416.    {
  417.       return undefined;
  418.    }
  419.    this.textField = tF;
  420.    this.textField[!this.horizontal ? "vScroller" : "hScroller"] = this;
  421.    this.onTextChanged();
  422.    this.onChanged = function()
  423.    {
  424.       this.onTextChanged();
  425.    };
  426.    this.onScroller = function()
  427.    {
  428.       if(!this.isScrolling)
  429.       {
  430.          if(!this.horizontal)
  431.          {
  432.             this.setScrollPosition(this.textField.scroll);
  433.          }
  434.          else
  435.          {
  436.             this.setScrollPosition(this.textField.hscroll);
  437.          }
  438.       }
  439.    };
  440.    this.textField.addListener(this);
  441.    this.textField.watch("text",this.callback);
  442.    this.textField.watch("htmlText",this.callback);
  443. };
  444. MScrollBarClass.prototype.callback = function(prop, oldVal, newVal)
  445. {
  446.    clearInterval(this.hScroller.synchScroll);
  447.    clearInterval(this.vScroller.synchScroll);
  448.    this.hScroller.synchScroll = setInterval(this.hScroller,"onTextChanged",50);
  449.    this.vScroller.synchScroll = setInterval(this.vScroller,"onTextChanged",50);
  450.    return newVal;
  451. };
  452. MScrollBarClass.prototype.onTextChanged = function()
  453. {
  454.    if(!this.enable || this.textField == undefined)
  455.    {
  456.       return undefined;
  457.    }
  458.    clearInterval(this.synchScroll);
  459.    if(this.horizontal)
  460.    {
  461.       var pos = this.textField.hscroll;
  462.       this.setScrollProperties(this.textField._width,0,this.textField.maxhscroll);
  463.       this.setScrollPosition(Math.min(pos,this.textField.maxhscroll));
  464.    }
  465.    else
  466.    {
  467.       var pos = this.textField.scroll;
  468.       var pageSize = this.textField.bottomScroll - this.textField.scroll;
  469.       this.setScrollProperties(pageSize,1,this.textField.maxscroll);
  470.       this.setScrollPosition(Math.min(pos,this.textField.maxscroll));
  471.    }
  472. };
  473. MScrollBarClass.prototype.executeCallBack = function()
  474. {
  475.    if(this.textField == undefined)
  476.    {
  477.       super.executeCallBack();
  478.    }
  479.    else if(this.horizontal)
  480.    {
  481.       this.textField.hscroll = this.getScrollPosition();
  482.    }
  483.    else
  484.    {
  485.       this.textField.scroll = this.getScrollPosition();
  486.    }
  487. };
  488. Object.registerClass("MScrollBarSymbol",MScrollBarClass);
  489.