Spiga.com.mx

About me...

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus rutrum elit et nunc. Phasellus tincidunt pede in nibh. Maecenas eget ligula non dui nonummy venenatis.Donec turpis. Sed mattis, diam quis fermentum dapibus, ante libero consequat felis, sed laoreet nibh mi in elit. Phasellus massa massa, commodo nonummy, rutrum sit amet, consequat pulvinar, eros. Nullam sit amet massa. Sed lobortis orci vehicula tellus.

In hac habitasse platea dictumst. Sed blandit diam in leo. Pellentesque sollicitudin tortor sit amet dui. Fusce vehicula purus suscipit nunc. Curabitur felis tortor, varius ac, placerat nec, vestibulum sed, est. Pellentesque fermentum. Suspendisse egestas. Nulla id mi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas eu augue. Nullam eu ipsum.

Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque ac lorem ac tortor fermentum molestie. Nunc suscipit erat non mi. Nullam dui dolor, tincidunt at, venenatis ut, bibendum in, purus. Fusce pretium ullamcorper nisl.

class flash.scrollPane.as 6 comments Posted: 17.7.2007 | By: zetta

(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: , , , , ,

06 comments to “class flash.scrollPane.as”

  1. Uuuy! Excelente bro, muchas gracias, que bueno que te animaste a armar ctrl-zeta!

  2. Grande maestro!!! Era justo lo que estaba necesitando para resolver un CD interactivo. Pero tengo un problema. Estoy poniendo en el MC “contenido” un cuadro de texto estático (porque le tengo que dar formato y vínculos) que mide más de 2000 px de alto. El problema es que llego hasta un punto con el scroll y de ahí para abajo, si bien sigue scrollando, no me muestra el texto que debería scrollar. Hay algún lugar donde se limite el largo del MC que scrollea?
    Si me pudieras ayudar, me harías un gran favor.
    Y gracias desde ya por la clase!

  3. @Gerardo!
    Que gusto que te haya servido la clase =)
    Lo que me comentas es un “bug” que tambien me ha pasado, resolverlo no he podido, pero hay forma de “truquearlo”, simplemente no crees uno solo cuadro de texto, sino mas bien crea varios, mas o menos donde se corte el contenido, cortalo y crea otro nuevo y ahi pon el resto. solo asi se desplegará todo el contenido.

    Despues de muuuuuuuucho contenido ocurre otro bug, que despliega la informacion bien rara =P pero ese si ya no he podido solucionarlo jeje

  4. Te cuento que poniendo texto dinámico logré meter mucho texto en un solo scroll y me funcionó de maravilla. Después de di formato poniéndole al texto. Y cuando ya era demasiado, creé unos botones que cargan en un nivel superior un hermoso parche que tapa el texto anterior y te muestra el tema nuevo ;=)
    Felicitaciones por la clase! Y gracias por la ayuda!

  5. Ah, me olvidé de algo. Necesito manejar la cantidad de líneas de texto que me suben o bajan los botones, que como está en cuerpo 14 a veces se hace medio dificil controlar que no se me vaya demasiado para arriba el texto y me pierda en la lectura. Me podrás indicar donde hago que suba o baje menos líneas de texto?
    Gracias otra vez

  6. ( ya corregi el codigo, no me habia dado cuenta que no estaba identado =P)
    Si te das cuentas en las lineas 41 y 58
    nombre._y += 10; y nombre._y -= 10;
    Cambia esos valores (10) para hacer que suba y baje dependiendo de lo que necesites

    Tenia una version mas padre de este scroll, me voy a poner a buscarla que de hecho también la usé en un CD interactivo,

    =)

Register

GUEST Leave a Reply