package com.meandmybadself.ui { import flash.display.*; import flash.events.*; import org.casaframework.math.Percent; import org.casaframework.util.NumberUtil; public class LoadSlider extends Slider{ public var $loadedMask:MovieClip; public var $loadedBG:MovieClip; private var $width:Number; public function LoadSlider(_width:Number = 0) { super(); $thumb.x = 0; $thumbBar.width = 0; $loadedMask.width = 0; setWidth(_width); } public function setLoadedValue(_per:Percent):void { var _perNum:Number = NumberUtil.makeBetween(_per.decimalPercentage, 0, 1); $loadedMask.width = $bg.width * _perNum; } /** * Returns the percentage of the position of the thumb compared to the loaded width. * @return */ public function getLoadedValue():Percent { var _perNum:Number = $thumb.x / $loadedMask.width; return new Percent(_perNum); } public override function setWidth(_width:Number):void { super.setWidth(_width); //persist old loadMask size. var _lmW:Number = $loadedMask.width / $bg.width; $loadedBG.width = _width; $loadedMask.width = $loadedBG.width * _lmW; } public override function unlock():void { super.unlock(); $loadedBG.buttonMode = true; $loadedBG.addEventListener(MouseEvent.MOUSE_DOWN, $thumb_PRESS); $loadedBG.addEventListener(MouseEvent.MOUSE_UP, $thumb_RELEASE); } public override function lock():void { super.lock(); $loadedBG.buttonMode = false; $loadedBG.removeEventListener(MouseEvent.MOUSE_DOWN, $thumb_PRESS); $loadedBG.removeEventListener(MouseEvent.MOUSE_UP, $thumb_RELEASE); } internal override function $drag(e:Event = null):void { $thumbBar.width = $thumb.x = NumberUtil.makeBetween(mouseX, $bg.x, $bg.x + $loadedMask.width); dispatchEvent(new Event(Event.CHANGE, true)); } public override function setValue(_per:Percent):void { //can only set values within the loaded area. var _loaded:Number = $loadedMask.width / $bg.width; var _valueNumber:Number = NumberUtil.makeBetween(_per.decimalPercentage, 0, _loaded); $thumbBar.width = $thumb.x = $bg.width * _valueNumber; } } }