function MGscrollbar_Class (trgt, style) { this.setStyles (style) this.Depth = this.trgt.getDepth () + 2 this.defineProps (trgt, props) this.setupElements () } var Class = MGscrollbar_Class.prototype; Class.setStyles = function (style) { if (style != undefined) { this.styles = style } else { this.defaultStyle () } } Class.defaultStyle = function () { trace ('defaultStyle') var _s = this.styles = new Object (); var _b = _s.Bg = new Object (); var _t = _s.Track = new Object (); var _btn = _s.Btn = new Object (); var _sl = _s.Slider = new Object (); //bg _b.W = Number (12); _b.Color = "0xcccccc"; _b.Trans = Number (0); _b.x = Number (0); _b.y = Number (0); //Track _t.W = Number (8); _t.Color = "0xffffff"; _t.Trans = Number (100); _t.x = Number (2); _t.y = Number (8); // Btn bg _btn.bg = new Object (); _btn.bg.W = Number (8); _btn.bg.H = Number (8); _btn.bg.Color = "0x2E2E2E"; _btn.bg.Trans = Number (0); _btn.bg.x = Number (2); // Btn arrow _btn.arrow = new Object (); _btn.arrow.W = Number (7); _btn.arrow.H = Number (6); _btn.arrow.Color = "0x2E2E2E"; _btn.arrow.Trans = Number (100); _btn.arrow.x = Number (1); _btn.arrow.y = Number (2); //Slider _sl.W = Number (6); _sl.Color = "0x999999"; _sl.Trans = Number (100); _sl.x = Number (3); _sl.y = Number (8); } Class.defineProps = function (trgt) { this.trgt = trgt this._tX = trgt._x this._tY = trgt._y var depth = this.trgt.getDepth () + 2 this.scroller_array = new Array () var _Sc = this.Scroller = this.trgt._parent.createEmptyMovieClip (trgt._name + "_Scroller", depth) _Sc._y = this._tY _Sc._x = this._tX if (typeof (this.trgt) != "movieclip") { this.trgtType = "textfield" } else { this.trgtType = "movieclip" } this [this.trgtType + "Props"]() } Class.textfieldProps = function () { var _s = this.styles var _t = this.textfield = new Object () this._cW = this.trgt.maxhscroll this._cH = this.trgt.maxscroll this._vW = this.trgt._width this._vH = this.trgt._height if (this.checkDir ("vert") == true) { var Vs = _t.VertScroller = this.Scroller.createEmptyMovieClip ("VertScroller", this.Depth ++) Vs.prop = "scroll" Vs.Sprop = "_y" Vs.Sbound = "_height" Vs._Cstart = 1 Vs._Vbound = this.trgt.maxviewable () Vs._Cbound = this._cH + Vs._Vbound Vs.TSize = Number (this._vH - (_s.Track.y * 2)) var _aP = Vs.arrowProps = new Object () _aP._dirs = ["up", "down"] var b = _aP.bg = new Object () var a = _aP.ar = new Object () _aP.x1 = _s.Btn.bg.x _aP.y1 = 0 _aP.x2 = _s.Btn.bg.x _aP.y2 = this._vH - _s.Btn.bg.h b.w = _s.Btn.bg.w b.h = _s.Btn.bg.h a.w = _s.Btn.arrow.W a.h = _s.Btn.arrow.H a.x = _s.Btn.arrow.x a.y = _s.Btn.arrow.y var stepPro = int (33.4 * (this.trgt.maxviewable () / 100)) Vs.Spro = (100 / Vs._Cbound) * stepPro Vs.Ppro = (100 / Vs._Cbound) * (Vs._Vbound - Vs._Cstart) this.scroller_array.push (Vs) } } Class.update = function () { var mc = this [this.trgtType].VertScroller if (Boolean (mc)) { if (this.checkDir ("vert") == true) { this._cH = this.trgt.maxscroll mc._Cbound = this._cH + mc._Vbound } else { this.removeScroller (mc) } } else { if (this.checkDir ("vert") == true) { this.textfieldProps (); } } } Class.removeScroller = function () { } Class.setupElements = function () { var MyClass = this var _s = this.styles this.enable = new Boolean (false) if (Boolean (this [this.trgtType].HorScroller)) { this.enable = new Boolean (true) var Hs = this [this.trgtType].HorScroller Hs ._y = this._vH Hs.Bg_mc = this.Buildcomps (Hs , "Bg_mc_h", _s.Bg, this._vW, _s.Bg.W, "Hor") Hs.Track_mc = this.Buildcomps (Hs , "Track_mc_h", _s.Track, Hs.TSize, _s.Track.W, "Hor") Hs.Slider_mc = this.Buildcomps (Hs , "Slider_mc_h", _s.Slider, Hs.TSize, _s.Slider.W, "Hor") Hs.Slider_mc.bounds = this.Bounds (Hs.Slider_mc); this.buildArrows () } if (Boolean (this [this.trgtType].VertScroller)) { this.enable = new Boolean (true) var Vs = this [this.trgtType].VertScroller Vs ._x = this._vW Vs.Bg_mc = this.Buildcomps (Vs , "Bg_mc_v", _s.Bg, _s.Bg.W, this._vH, "Vert") Vs.Track_mc = this.Buildcomps (Vs , "Track_mc_v", _s.Track, _s.Track.W, Vs.TSize, "Vert") Vs.Slider_mc = this.Buildcomps (Vs , "Slider_mc_v", _s.Slider, _s.Slider.W, Vs.TSize, "Vert") Vs.Slider_mc.bounds = this.Bounds (Vs.Slider_mc); this.buildArrows () } if (this.enable) { this.WheelHit () this.updateSliderSize () this.sizeRatio () this.SliderAction () this.TrackClick () this.Wheel () } } Class.checkDir = function (Type) { switch (Type) { case "vert" : if (this._cH > 1) { var _B = new Boolean (true) } else { var _B = new Boolean (false) } break; } return _B } Class.WheelHit = function () { var w = this._vW var h = this._vH var mc2 = this.Mask_mc = this.Scroller._parent.createEmptyMovieClip (this.trgt._name + "_Mask", this.trgt.getDepth () + 1) mc2.box (0, 0, w, h, "0x0000ff", 0); if (this [this.trgtType].VertScroller) { w = this._vW + this.styles.Bg.W } if (this [this.trgtType].HorScroller) { h = this._vH + this.styles.Bg.W } var mc1 = this.Hit_mc = this.Scroller.createEmptyMovieClip ("Hit_mc", this.Depth ++) mc1.box (0, 0, w, h, "0xff0000", 0); mc2._x = this._tX mc2._y = this._tY } Class.Wheel = function () { var MyClass = this if (!Boolean (this [this.trgtType].VertScroller)) { var Sc = "HorScroller" }else{ var Sc = "VertScroller" } for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] if (mc._name == Sc) { this.mouseListener = new Object (); this.mouseListener.mc = mc this.mouseListener.onMouseWheel = function (delta) { if (mc._parent.Hit_mc.hitTest (_root._xmouse, _root._ymouse)) { if (delta < 0) { MyClass.Move ("down", this.mc.Spro, "static", this.mc) } else { MyClass.Move ("up", this.mc.Spro, "static", this.mc) } } } Mouse.addListener (this.mouseListener); } } } Class.Buildcomps = function (trgt, Name, _s, _w, _h, Type) { var _n = trgt.createEmptyMovieClip (Name, this.Depth ++) switch (Type) { case "Hor" : _n._x = _s.y _n._y = _s.x _n.box (0, 0, _w, _h, _s.Color, _s.Trans); break; case "Vert" : _n._x = _s.x _n._y = _s.y _n.box (0, 0, _w, _h, _s.Color, _s.Trans); break; } return _n; } Class.buildArrows = function () { var MyClass = this var _s = this.styles for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] var dir1 = mc.arrowProps._dirs [0] var _aP = mc.arrowProps mc.arrow1 = mc .createEmptyMovieClip ("arrow1", this.Depth ++) mc.arrow1.box (0, 0, _aP.bg.w, _aP.bg.h, _s.Btn.bg.Color, _s.Btn.bg.Trans); mc.arrow1.arrow (_aP.ar.x, _aP.ar.y, _aP.ar.w, _aP.ar.h, _s.Btn.arrow.Color, _s.Btn.arrow.Trans, dir1) mc.arrow1._x = _aP.x1 mc.arrow1._y = _aP.y1 mc.arrow1.onPress = function () { MyClass.Move ("up", this._parent.Spro, "ani", this._parent) } var dir2 = mc.arrowProps._dirs [1] mc.arrow2 = mc.createEmptyMovieClip ("arrow2", this.Depth ++) mc.arrow2.box (0, 0, _aP.bg.w, _aP.bg.h, _s.Btn.bg.Color, _s.Btn.bg.Trans); mc.arrow2.arrow (_aP.ar.x, _aP.ar.y, _aP.ar.w, _aP.ar.h, _s.Btn.arrow.Color, _s.Btn.arrow.Trans, dir2) mc.arrow2._x = _aP.x2 mc.arrow2._y = _aP.y2 mc.arrow2.onPress = function () { MyClass.Move ("down", this._parent.Spro, "ani", this._parent) } } } Class.sizeRatio = function () { for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] mc._sRatio = (mc.TSize - mc.Slider_mc [mc.Sbound]) / 100 mc._sDem = 100 / (mc.TSize - mc.Slider_mc [mc.Sbound]) mc._cRatio = (mc._Cbound - mc._Vbound) / 100 mc._cDem = 100 / (mc._Cbound - mc._Vbound) } } Class.updateSliderSize = function () { for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] mc.Slider_mc [mc.Sprop + "scale"] = mc._Vbound / (mc._Cbound / 100) if (mc.Slider_mc [mc.Sbound] <= 15) { mc.Slider_mc [mc.Sbound] = 15; } } } Class.Bounds = function (mc) { var data = new Object () data.xMin = mc._x data.yMin = mc._y data.xMax = mc._width - mc._x data.yMax = mc._height - mc._y return data } Class.SliderAction = function () { var MyClass = this var _s = this.styles for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] mc.Slider_mc.onPress = function () { this.onEnterFrame = function () { var pro = (this._parent._sDem * ((this [this._parent.Sprop] - _s.Slider.y))) if (pro > 98) { pro = 100 } else if (pro < 1) { pro = 0 } if (MyClass.trgtType != "movieclip") { MyClass.trgt [this._parent.prop] = int (this._parent._cRatio * pro) } else { MyClass.trgt [this._parent.prop] = Number (this._parent._Cstart - (this._parent._cRatio * pro)) } } if (this._parent._name == "VertScroller") { this.startDrag (false, this.bounds.xMin, this.bounds.yMin, this.bounds.xMax, Number (this.bounds.yMin + this._parent.TSize - this [this._parent.Sbound])) } if (this._parent._name == "HorScroller") { this.startDrag (false, this.bounds.xMin, this.bounds.yMin, Number (this.bounds.xMin + this._parent.TSize - this [this._parent.Sbound]) , this.bounds.yMin) } } mc.Slider_mc.onRelease = mc.Slider_mc.onReleaseOutside = function () { this.stopDrag () delete this.onEnterFrame } } } Class.TrackClick = function () { var MyClass = this for (var i = 0; i < this.scroller_array.length; i ++) { var mc = this.scroller_array [i] var _t = mc.Track_mc _t.onPress = function () { var _sl = this._parent.Slider_mc if (this._parent [this._parent.Sprop + "mouse"] > _sl [this._parent.Sprop]) { MyClass.Move ("down", this._parent.Ppro, "ani", this._parent) } else { MyClass.Move ("up", this._parent.Ppro, "ani", this._parent) } } } } Class.CheckBounds = function (Data) { if (Data._pro < 0) { Data._pro = 0 } if (Data._pro > 100) { Data._pro = 100 } this.stepType (Data) } Class.Move = function (_dir, Step, Type, Scroller) { var _s = this.styles; switch (_dir) { case "up" : var pro = Number ((Scroller._sDem * (Scroller.Slider_mc [Scroller.Sprop] - Scroller.Track_mc [Scroller.Sprop])) - Step) var _d = "back" var Data = { _pro : pro, mc : Scroller, type : Type, _d : _d } break; case "down" : var pro = Number ((Scroller._sDem * (Scroller.Slider_mc [Scroller.Sprop] - Scroller.Track_mc [Scroller.Sprop])) + Step) var _d = "forward" var Data = { _pro : pro, mc : Scroller, type : Type, _d : _d } break; } this.CheckBounds (Data) } Class.stepType = function (Data) { switch (Data.type) { case "ani" : switch (this.trgtType) { case "movieclip" : var sD = (Data.mc._sRatio * Data._pro) + this.styles.Slider.y var cD = Number (Data.mc._Cstart - (Data.mc._cRatio * Data._pro)) switch (Data.mc.Sprop) { case "_x" : this.trgt.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _x : cD }); Data.mc.Slider_mc.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _x : sD }); break; case "_y" : this.trgt.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _y : cD }); Data.mc.Slider_mc.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _y : sD }); break; } break; case "textfield" : this.trgt [Data.mc.prop] = int (Data.mc._cRatio * Data._pro) var sD = (Data.mc._sRatio * Data._pro) + this.styles.Slider.y switch (Data._d) { case "back" : if (int (Data.mc._cRatio * Data._pro) <= Data.mc._Cstart) { sD = (Data.mc._sRatio * 0) + this.styles.Slider.y } break; case "forward" : if (int (Data.mc._cRatio * Data._pro) >= (Data.mc._Cbound - Data.mc._Vbound)) { sD = (Data.mc._sRatio * 100) + this.styles.Slider.y } break; } switch (Data.mc.Sprop) { case "_x" : Data.mc.Slider_mc.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _x : sD }); break; case "_y" : Data.mc.Slider_mc.transform ( { type : "easeOutQuart", frames : 20, delay : 0 }, { _y : sD }); break; } break; } break; case "static" : switch (this.trgtType) { case "movieclip" : var sD = (Data.mc._sRatio * Data._pro) + this.styles.Slider.y var cD = Number (Data.mc._Cstart - (Data.mc._cRatio * Data._pro)) Data.mc.Slider_mc [Data.mc.Sprop] = sD this.trgt [Data.mc.prop] = cD break; case "textfield" : var sD = (Data.mc._sRatio * Data._pro) + this.styles.Slider.y this.trgt [Data.mc.prop] = int (Data.mc._cRatio * Data._pro) switch (Data._d) { case "back" : if (int (Data.mc._cRatio * Data._pro) <= 1) { sD = (Data.mc._sRatio * 0) + this.styles.Slider.y } break; case "forward" : if (int (Data.mc._cRatio * Data._pro) >= (Data.mc._Cbound - Data.mc._Vbound)) { sD = (Data.mc._sRatio * 100) + this.styles.Slider.y } break; } Data.mc.Slider_mc [Data.mc.Sprop] = sD break; } break; } } ASSetPropFlags (Class, null, 1) MovieClip.prototype.arrow = function (x, y, w, h, col, alpha, _dir) { this.beginFill (col, alpha); switch (_dir) { case "up" : this.moveTo ((w / 2) + (x / 2) , y); this.lineTo (w, h); this.lineTo (x, h); break; case "down" : this.moveTo ((w / 2) + (x / 2) , h); this.lineTo (w, y); this.lineTo (x, y); break; case "left" : this.moveTo (x, (h / 2)); this.lineTo (w, y); this.lineTo (w, h); break; case "right" : this.moveTo (w, (h / 2)); this.lineTo (x, y); this.lineTo (x, h); break; } this.endFill (); }; TextField.prototype.maxviewable = function () { if (this.maxscroll > 1) { return this.bottomScroll; } var b = (this.html) ? this.bottomScroll - 1 : this.bottomScroll; if ( ! this.length) { this.text = "»"; } var out = Math.floor (this._height / (this.textHeight / b)); if (this.text == "»") { this.text = ""; } return out; };