Juan Carlos Clemente
1986-06-13
zetta
Website Photo
zetta

class flash.Window.as Beta

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

Window v.alpha

Clase Window.as

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
class Window {
var width:Number;
var height:Number;
var home:MovieClip;
var im:MovieClip;
function Window(home:MovieClip,width:Number, height:Number) {
this.width = width;
this.height = height;
this.home = home;
}
public function draw(x:Number,y:Number,params:Object):Void{
var num:Number = home.getNextHighestDepth();
this.im = this.home.attachMovie("window","customWindow"+num,num);
this.im._y = y;
this.im._x = x;
this.im.bar._width = this.width;
if(params.showbar == false) this.im.bar._visible = false;
this.im.content._width = this.width;
this.im.content._height = this.height;
if(params.draggable != false){
this.im.bar.onPress =  Delegate.create (this, startDrag);
this.im.bar.onRelease = Delegate.create(this,stopDrag);
this.im.bar.onReleaseOutside = Delegate.create(this,stopDrag);
}
this.im.content.onPress =  Delegate.create (this, top);
if((params.forceDrag == true && params.showbar == false) || (params.allDraggable == true)){
this.im.content.onPress =  Delegate.create (this, startDrag);
this.im.content.onRelease = Delegate.create(this,stopDrag);
this.im.content.onReleaseOutside = Delegate.create(this,stopDrag);
}
}
private function top():Void{
this.im.swapDepths(this.home.getNextHighestDepth());
}
private function startDrag():Void{
this.setProperty(this.im.content,"_alpha", 25, .5);
this.top();
this.im.startDrag(false);
}
private function stopDrag():Void{
this.setProperty(this.im.content,"_alpha", 100, .5);
this.im.stopDrag();
}
private function setProperty(target:MovieClip,property:String,value:Number,time:Number):Void{
var set:Tween = new Tween(target, property, Regular.easeOut, target[property], value, time, true);
}
public function get xny():Object{
return {x : this.im._x, y : this.im._y};
}
public function addContent(add:MovieClip):Void{
//todo
}
}

Uso

1
2
var w1:Window = new Window(target:MovieClip,width:Number,height:Number);
w1.draw(x:Number,y:Number);

Donde:

  • target => Donde se construira la ventana
  • width => Ancho de la ventanta
  • height => Alto de la ventana

Métodos

  • draw:VoidDibuja la ventana en las coordenadas especificadas

Propiedades

  • xny
  • Devuelve un objeto con las coordenadas actuales de la ventana

Descargar windowBeta.zip
[tags]flash, actionscript, class, window, opensource[/tags]

class flash.scrollPane.as

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

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]flash, actionscript, class, scroll, scrollPane[/tags]