home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Demo / Elearn / Fizica / vol2 / interfata.swf / scripts / FScrollPaneSymbol.as < prev    next >
Text File  |  2005-01-03  |  9KB  |  295 lines

  1. function FScrollPaneClass()
  2. {
  3.    function boolToString(str)
  4.    {
  5.       if(str == "false")
  6.       {
  7.          return false;
  8.       }
  9.       if(str == "true")
  10.       {
  11.          return true;
  12.       }
  13.       return str;
  14.    }
  15.    this.init();
  16.    this.width = this._width;
  17.    this.height = this._height;
  18.    this._xscale = this._yscale = 100;
  19.    this.contentWidth = this.contentHeight = 0;
  20.    if(this.hScroll == undefined)
  21.    {
  22.       this.hScroll = this.vScroll = "auto";
  23.       this.dragContent = false;
  24.    }
  25.    this.offset = new Object();
  26.    this.vScroll = boolToString(this.vScroll);
  27.    this.hScroll = boolToString(this.hScroll);
  28.    this.attachMovie("FScrollBarSymbol","hScrollBar_mc",100,{hostStyle:this.styleTable});
  29.    this.hScrollBar_mc.setHorizontal(true);
  30.    this.hScrollBar_mc.setSmallScroll(5);
  31.    this.hScrollBar_mc.setChangeHandler("onScroll",this);
  32.    this.attachMovie("FScrollBarSymbol","vScrollBar_mc",99,{hostStyle:this.styleTable});
  33.    this.vScrollBar_mc.setSmallScroll(5);
  34.    this.vScrollBar_mc.setChangeHandler("onScroll",this);
  35.    this.setSize(this.width,this.height);
  36.    if(this.scrollContent != "")
  37.    {
  38.       this.setScrollContent(this.scrollContent);
  39.    }
  40.    this.setDragContent(this.dragContent);
  41. }
  42. FScrollPaneClass.prototype = new FUIComponentClass();
  43. Object.registerClass("FScrollPaneSymbol",FScrollPaneClass);
  44. FScrollPaneClass.prototype.getScrollContent = function()
  45. {
  46.    return this.content_mc;
  47. };
  48. FScrollPaneClass.prototype.getPaneWidth = function()
  49. {
  50.    return this.width;
  51. };
  52. FScrollPaneClass.prototype.getPaneHeight = function()
  53. {
  54.    return this.height;
  55. };
  56. FScrollPaneClass.prototype.getScrollPosition = function()
  57. {
  58.    var xPos = this.hScrollBar_mc != undefined ? this.hScrollBar_mc.getScrollPosition() : 0;
  59.    var yPos = this.vScrollBar_mc != undefined ? this.vScrollBar_mc.getScrollPosition() : 0;
  60.    return {x:xPos,y:yPos};
  61. };
  62. FScrollPaneClass.prototype.setScrollContent = function(target)
  63. {
  64.    this.offset.x = 0;
  65.    this.offset.y = 0;
  66.    if(this.content_mc != undefined)
  67.    {
  68.       if(target != this.content_mc)
  69.       {
  70.          this.content_mc._visible = false;
  71.          this.content_mc.removeMovieClip();
  72.          this.content_mc.unloadMovie();
  73.       }
  74.    }
  75.    if(typeof target == "string")
  76.    {
  77.       this.attachMovie(target,"tmp_mc",3);
  78.       this.content_mc = this.tmp_mc;
  79.    }
  80.    else if(target == undefined)
  81.    {
  82.       this.content_mc.unloadMovie();
  83.    }
  84.    else
  85.    {
  86.       this.content_mc = target;
  87.    }
  88.    this.localToGlobal(this.offset);
  89.    this.content_mc._parent.globalToLocal(this.offset);
  90.    this.content_mc._x = this.offset.x;
  91.    this.content_mc._y = this.offset.y;
  92.    this.localToGlobal(this.offset);
  93.    this.content_mc._parent.globalToLocal(this.offset);
  94.    this.content_mc._x = this.offset.x;
  95.    this.content_mc._y = this.offset.y;
  96.    this.contentWidth = this.content_mc._width;
  97.    this.contentHeight = this.content_mc._height;
  98.    this.content_mc.setMask(this.mask_mc);
  99.    this.setSize(this.width,this.height);
  100. };
  101. FScrollPaneClass.prototype.setSize = function(w, h)
  102. {
  103.    if(arguments.length < 2 || isNaN(w) || isNaN(h))
  104.    {
  105.       return undefined;
  106.    }
  107.    super.setSize(w,h);
  108.    this.width = Math.max(w,60);
  109.    this.height = Math.max(h,60);
  110.    this.boundingBox_mc._xscale = 100;
  111.    this.boundingBox_mc._yscale = 100;
  112.    this.boundingBox_mc._width = this.width;
  113.    this.boundingBox_mc._height = this.height;
  114.    this.setHandV();
  115.    this.initScrollBars();
  116.    if(this.mask_mc == undefined)
  117.    {
  118.       this.attachMovie("FBoundingBoxSymbol","mask_mc",3000);
  119.    }
  120.    this.mask_mc._xscale = 100;
  121.    this.mask_mc._yscale = 100;
  122.    this.mask_mc._width = this.hWidth;
  123.    this.mask_mc._height = this.vHeight;
  124.    this.mask_mc._alpha = 0;
  125. };
  126. FScrollPaneClass.prototype.setScrollPosition = function(x, y)
  127. {
  128.    x = Math.max(this.hScrollBar_mc.minPos,x);
  129.    x = Math.min(this.hScrollBar_mc.maxPos,x);
  130.    y = Math.max(this.vScrollBar_mc.minPos,y);
  131.    y = Math.min(this.vScrollBar_mc.maxPos,y);
  132.    this.hScrollBar_mc.setScrollPosition(x);
  133.    this.vScrollBar_mc.setScrollPosition(y);
  134. };
  135. FScrollPaneClass.prototype.refreshPane = function()
  136. {
  137.    this.setScrollContent(this.content_mc);
  138. };
  139. FScrollPaneClass.prototype.loadScrollContent = function(url, handler, location)
  140. {
  141.    this.content_mc.removeMovieClip();
  142.    this.content_mc.unloadMovie();
  143.    this.content_mc._visible = 0;
  144.    this.loadContent.duplicateMovieClip("loadTemp",3);
  145.    this.dupeFlag = true;
  146.    this.contentLoaded = function()
  147.    {
  148.       this.loadReady = false;
  149.       this.content_mc = this.loadTemp;
  150.       this.refreshPane();
  151.       this.executeCallBack();
  152.    };
  153.    this.setChangeHandler(handler,location);
  154.    this.loadTemp.loadMovie(url);
  155. };
  156. FScrollPaneClass.prototype.setHScroll = function(prop)
  157. {
  158.    this.hScroll = prop;
  159.    this.setSize(this.width,this.height);
  160. };
  161. FScrollPaneClass.prototype.setVScroll = function(prop)
  162. {
  163.    this.vScroll = prop;
  164.    this.setSize(this.width,this.height);
  165. };
  166. FScrollPaneClass.prototype.setDragContent = function(dragFlag)
  167. {
  168.    if(dragFlag)
  169.    {
  170.       this.boundingBox_mc.useHandCursor = true;
  171.       this.boundingBox_mc.onPress = function()
  172.       {
  173.          this._parent.startDragLoop();
  174.       };
  175.       this.boundingBox_mc.tabEnabled = false;
  176.       this.boundingBox_mc.onRelease = this.boundingBox_mc.onReleaseOutside = function()
  177.       {
  178.          this._parent.pressFocus();
  179.          this._parent.onMouseMove = null;
  180.       };
  181.    }
  182.    else
  183.    {
  184.       delete this.boundingBox_mc.onPress;
  185.       this.boundingBox_mc.useHandCursor = false;
  186.    }
  187. };
  188. FScrollPaneClass.prototype.setSmallScroll = function(x, y)
  189. {
  190.    this.hScrollBar_mc.setSmallScroll(x);
  191.    this.vScrollBar_mc.setSmallScroll(y);
  192. };
  193. FScrollPaneClass.prototype.setHandV = function()
  194. {
  195.    if(this.contentHeight - this.height > 2 && this.vScroll != false || this.vScroll == true)
  196.    {
  197.       this.hWidth = this.width - this.vScrollBar_mc._width;
  198.    }
  199.    else
  200.    {
  201.       this.hWidth = this.width;
  202.    }
  203.    if(this.contentWidth - this.width > 2 && this.hScroll != false || this.hScroll == true)
  204.    {
  205.       this.vHeight = this.height - this.hScrollBar_mc._height;
  206.    }
  207.    else
  208.    {
  209.       this.vHeight = this.height;
  210.    }
  211. };
  212. FScrollPaneClass.prototype.startDragLoop = function()
  213. {
  214.    this.tabFocused = false;
  215.    this.myOnSetFocus();
  216.    this.lastX = this._xmouse;
  217.    this.lastY = this._ymouse;
  218.    this.onMouseMove = function()
  219.    {
  220.       this.scrollXMove = this.lastX - this._xmouse;
  221.       this.scrollYMove = this.lastY - this._ymouse;
  222.       this.scrollXMove += this.hScrollBar_mc.getScrollPosition();
  223.       this.scrollYMove += this.vScrollBar_mc.getScrollPosition();
  224.       this.setScrollPosition(this.scrollXMove,this.scrollYMove);
  225.       if(this.scrollXMove < this.hScrollBar_mc.maxPos && this.scrollXMove > this.hScrollBar_mc.minPos)
  226.       {
  227.          this.lastX = this._xmouse;
  228.       }
  229.       if(this.scrollYMove < this.vScrollBar_mc.maxPos && this.scrollYMove > this.vScrollBar_mc.minPos)
  230.       {
  231.          this.lastY = this._ymouse;
  232.       }
  233.       this.updateAfterEvent();
  234.    };
  235. };
  236. FScrollPaneClass.prototype.initScrollBars = function()
  237. {
  238.    this.hScrollBar_mc._y = this.height - this.hScrollBar_mc._height;
  239.    this.hScrollBar_mc.setSize(this.hWidth);
  240.    this.hScrollBar_mc.setScrollProperties(this.hWidth,0,this.contentWidth - this.hWidth);
  241.    this.vScrollBar_mc._visible = this.hWidth != this.width ? true : false;
  242.    this.vScrollBar_mc._x = this.width - this.vScrollBar_mc._width;
  243.    this.vScrollBar_mc.setSize(this.vHeight);
  244.    this.vScrollBar_mc.setScrollProperties(this.vHeight,0,this.contentHeight - this.vHeight);
  245.    this.hScrollBar_mc._visible = this.vHeight != this.height ? true : false;
  246. };
  247. FScrollPaneClass.prototype.onScroll = function(component)
  248. {
  249.    var pos = component.getScrollPosition();
  250.    var XorY = component._name != "hScrollBar_mc" ? "y" : "x";
  251.    if(component._name == "hScrollBar_mc")
  252.    {
  253.       this.content_mc._x = - pos + this.offset.x;
  254.    }
  255.    else
  256.    {
  257.       this.content_mc._y = - pos + this.offset.y;
  258.    }
  259. };
  260. FScrollPaneClass.prototype.myOnKeyDown = function()
  261. {
  262.    var posX = this.hScrollBar_mc.getScrollPosition();
  263.    var posY = this.vScrollBar_mc.getScrollPosition();
  264.    if(this.hScrollBar_mc.maxPos > this.hScrollBar_mc.minPos)
  265.    {
  266.       if(Key.isDown(37))
  267.       {
  268.          this.setScrollPosition(posX - 3,posY);
  269.       }
  270.       else if(Key.isDown(39))
  271.       {
  272.          this.setScrollPosition(posX + 3,posY);
  273.       }
  274.    }
  275.    if(this.vScrollBar_mc.maxPos > this.vScrollBar_mc.minPos)
  276.    {
  277.       if(Key.isDown(38))
  278.       {
  279.          this.setScrollPosition(posX,posY - 3);
  280.       }
  281.       else if(Key.isDown(40))
  282.       {
  283.          this.setScrollPosition(posX,posY + 3);
  284.       }
  285.       else if(Key.isDown(34))
  286.       {
  287.          this.setScrollPosition(posX,posY + this.vScrollBar_mc.pageSize);
  288.       }
  289.       else if(Key.isDown(33))
  290.       {
  291.          this.setScrollPosition(posX,posY - this.vScrollBar_mc.pageSize);
  292.       }
  293.    }
  294. };
  295.