(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Pane v1.3

  1. Multiples instancias
  2. Integración con la rueda del ratón (al parecer no funciona en MacOs X)

Clase Pane.as

  1. import mx.utils.Delegate;
  2. class Pane {
  3.     var mask: MovieClip,
  4.         sc1: MovieClip,
  5.         sc2: MovieClip,
  6.         origin: MovieClip,
  7.         sBar: MovieClip,
  8.         Target: MovieClip;
  9.     var sTotal: Number,
  10.         top: Number,
  11.         h: Number,
  12.         w: Number;
  13.     var ml: Object;
  14.     var delayer: Number;
  15.     function Pane(clip, width, height, pos) {
  16.         delayer = 0;
  17.         ml = new Object();
  18.         Mouse.addListener(ml);
  19.         this.origin = clip;
  20.         this.w = width;
  21.         this.h = height;
  22.         mask = clip._parent.createEmptyMovieClip("masking_" + clip._name, clip._parent.getNextHighestDepth());
  23.         mask._x = clip._x;
  24.         mask._y = clip._y;
  25.         mask.lineStyle(1, 0x000000, 100, true, "none", "round", "miter", 1);
  26.         mask.beginFill(0x000000);
  27.         mask.moveTo(0, 0);
  28.         mask.lineTo(width, 0);
  29.         mask.lineTo(width, height);
  30.         mask.lineTo(0, height);
  31.         mask.moveTo(0, 0);
  32.         clip.setMask(mask);
  33.         sc1 = clip._parent.attachMovie("paneScrollButon", "sc1_" + clip._name, clip._parent.getNextHighestDepth());
  34.         sc1._x = (pos == "left") ? Math.ceil(clip._x - sc1._width) : Math.ceil(clip._x + width);
  35.         sc1._y = Math.ceil(clip._y);
  36.         sc1.onPress = function() {
  37.             var nombre: MovieClip = this._parent["sBar_" + this._name.substr(4, this._name.length)];
  38.             nombre.onEnterFrame = track;
  39.             this.onEnterFrame = function() {
  40.                 if (nombre._y > nombre._top) {
  41.                     nombre._y -= 10;
  42.                 } else {
  43.                     nombre._y = nombre._top;
  44.                 }
  45.             };
  46.         };
  47.         sc1.onRelease = sc1.onReleaseOutside = function() {
  48.             delete this.onEnterFrame;
  49.         };
  50.         sc2 = clip._parent.attachMovie("paneScrollButon2", "sc2_" + clip._name, clip._parent.getNextHighestDepth());
  51.         sc2._x = (pos == "left") ? Math.ceil(clip._x - sc1._width) : Math.ceil(clip._x + width);
  52.         sc2._y = Math.ceil((clip._y + height) - sc1._height);
  53.         sc2.onPress = function() {
  54.             var nombre: MovieClip = this._parent["sBar_" + this._name.substr(4, this._name.length)];
  55.             nombre.onEnterFrame = track;
  56.             this.onEnterFrame = function() {
  57.                 if (nombre._y < nombre._bottom) {
  58.                     nombre._y += 10;
  59.                 } else {
  60.                     nombre._y = nombre._bottom;
  61.                 }
  62.             };
  63.         };
  64.         sc2.onRelease = sc1.onReleaseOutside = function() {
  65.             delete this.onEnterFrame;
  66.         };
  67.         sTotal = clip.sTotal = Math.ceil(sc2._y - (sc1._y + sc1._height));
  68.         sBar = clip._parent.attachMovie("paneScrollBar", "sBar_" + clip._name, clip._parent.getNextHighestDepth());
  69.         sBar.Target = clip;
  70.         sBar._x = Math.ceil(sc1._x);
  71.         sBar._y = Math.ceil(sc1._y + sc1._height);
  72.         sBar._height = (((height * 100) / clip._height) / 100) * height;;
  73.         sBar.onRelease = sBar.onReleaseOutside = function() {
  74.             this.isPressed = false;
  75.             this.stopDrag();
  76.         };
  77.         var left: Number = Math.ceil(sc1._x);
  78.         var top: Number = Math.ceil(sc1._y + sc1._height + 1);
  79.         var bottom: Number = Math.ceil((sc1._y + sTotal + sc1._height) - (sBar._height) - 1);
  80.         sBar._top = top;
  81.         sBar._left = left;
  82.         sBar._bottom = bottom;
  83.         sBar.delayer = 0;
  84.         sBar.isPressed = false;
  85.         sBar.onPress = function() {
  86.             this.startDrag(false, this._left, this._top, this._left, this._bottom);
  87.             this.onEnterFrame = track;
  88.             this.delayer = 0;
  89.             this.isPressed = true;
  90.         };
  91.         function track() {
  92.             var percent: Number = Math.round((this._y - this._top) * 100) / (this._bottom - this._top);
  93.             var nombre: MovieClip = this._parent[this._name.substr(5, this._name.length)];
  94.             var mask: MovieClip = nombre._parent["masking_" + nombre._name];
  95.             var diff: Number = nombre._height - mask._height;
  96.             var newVal = ( - ((diff * percent) / 100)) + mask._y;
  97.             nombre._y += (newVal - nombre._y) * 0.4;
  98.             this.delayer = this.isPressed == false ? this.delayer + 1 : this.delayer;
  99.             if (this.delayer == 10) {
  100.                 delete this.onEnterFrame
  101.             }
  102.         }
  103.         ml.onMouseWheel = Delegate.create(this, wheel);
  104.     }
  105.     private function _track() {
  106.         var percent: Number = Math.round((sBar._y - sBar._top) * 100) / (sBar._bottom - sBar._top);
  107.         var diff: Number = origin._height - mask._height;
  108.         var newVal = ( - ((diff * percent) / 100)) + mask._y;
  109.         origin._y += (newVal - origin._y) * 0.4;
  110.         delayer++;
  111.         if (delayer == 10) {
  112.             delete sBar.onEnterFrame
  113.         }
  114.     }
  115.     private function wheel(delta) {
  116.         var ob: MovieClip = this.origin._parent;
  117.         var obj: MovieClip = this.mask;
  118.         if (ob._xmouse > = obj._x && ob._xmouse < = obj._x + this.w && ob._ymouse > = obj._y && ob._ymouse < = obj._y + this.h) {
  119.             delayer = 0;
  120.             if (delta < 0) {
  121.                 sBar.onEnterFrame = Delegate.create(this, _track);
  122.                 if (sBar._y + 25 < sBar._bottom) {
  123.                     sBar._y += 25;
  124.                 } else {
  125.                     sBar._y = sBar._bottom;
  126.                 }
  127.             } else {
  128.                 sBar.onEnterFrame = Delegate.create(this, _track);
  129.                 if (sBar._y - 25 > sBar._top) {
  130.                     sBar._y -= 25;
  131.                 } else {
  132.                     sBar._y = sBar._top;
  133.                 }
  134.             }
  135.         }
  136.     }
  137.     public function is() {
  138.         return true;
  139.     }
  140.     public function die() {
  141.         this.mask.removeMovieClip();
  142.         this.sBar.removeMovieClip();
  143.         this.sc1.removeMovieClip();
  144.         this.sc2.removeMovieClip();
  145.     }
  146.     public function hide() {
  147.         this.mask._visible = false;
  148.         this.sBar._visible = false;
  149.         this.sc1._visible = false;
  150.         this.sc2._visible = false;
  151.         this.origin._visible = false;
  152.     }
  153.     public function show() {
  154.         this.mask._visible = true;
  155.         this.sBar._visible = true;
  156.         this.sc1._visible = true;
  157.         this.sc2._visible = true;
  158.         this.origin._visible = true;
  159.     }
  160.     public function reset() {
  161.         sBar._x = Math.ceil(sc1._x);
  162.         sBar._y = Math.ceil(sc1._y + sc1._height);
  163.         origin._y = sc1._y;
  164.         show();
  165.     }
  166.     public function resize() {
  167.         sBar._height = (((h * 100) / origin._height) / 100) * h;
  168.         sBar._left = Math.ceil(sc1._x);
  169.         sBar._top = Math.ceil(sc1._y + sc1._height + 1);
  170.         sBar._bottom = Math.ceil((sc1._y + sTotal + sc1._height) - (sBar._height) - 1);
  171.     }
  172. }

Uso

  1. var newPane:Pane = new Pane(clip:MovieClip, Width:Number, height:Number, type:String);

Donde:

  • clip => MovieClip que se enmascarará
  • width => Ancho del cuadro a crear
  • height => Alto del cuadro a crear
  • type => De que lado estara la barra de scroll (left / right)

Métodos

  • is:BooleanDevuelve verdadero en caso de existir la instancia
  • hide:VoidOculta el objeto Pane
  • show:VoidVuelve a mostrar el objeto Pane
  • reset:VoidRegresa el scrollbar al inicio (arriba)
  • resize:VoidRegenera el tamaño del scroll (útil en contenido dinámico)

Descargar Pane.zip


Tags: , , , , ,