package
{ /** * * @author * @date 2010-6-23 * @description 拖动进度条 * @demo <ns:ProgressBarSlider id="pbs" * width="200" * value="50" * maximum="50" * minimum="0" * snapInterval="10" * themeColor="#F20D7A"/> * **/ import flash.display.DisplayObject; import flash.events.Event; import mx.containers.Canvas; import mx.controls.HSlider; import mx.controls.ProgressBar; import mx.controls.ProgressBarMode; import mx.controls.sliderClasses.Slider; import mx.events.SliderEvent; [Style(name="themeColor", type="uint", format="Color", inherit="yes")] public class ProgressBarSlider extends Canvas { private var progressBar:ProgressBar; private var silder:HSlider; private var _value:Number=0; private var _maximum:Number=100; private var _minimum:Number=0; private var _snapInterval : Number = 1; [Bindable("change")] /** * Read-only property that contains the amount of progress * that has been made - between the minimum and maximum values. */ public function get value():Number { return _value; } public function set value(value : Number) : void { _value = value; progressBar.setProgress(value,maximum); silder.value = 50; } [Inspectable(category="General", defaultValue="100")] public function get maximum():Number { return _maximum; } public function set maximum(value:Number):void { if (!isNaN(value) && value != _maximum) { progressBar.maximum = value; silder.maximum = value; } } // minimum [Inspectable(category="General", defaultValue="0")] public function get minimum() : Number { return _minimum; } public function set minimum(value:Number):void { if (!isNaN(value) && value != _minimum) { progressBar.minimum = value; silder.minimum = value; } } //步进 public function get snapInterval():Number { return _snapInterval; } public function set snapInterval(value:Number):void { _snapInterval=value; silder.snapInterval = value; } public function ProgressBarSlider() { progressBar = new ProgressBar(); silder = new HSlider(); width=100; } override protected function createChildren():void { super.createChildren(); progressBar.x = 0; progressBar.y = 0; progressBar.minimum = minimum; progressBar.maximum = maximum; progressBar.mode = ProgressBarMode.MANUAL; progressBar.labelPlacement = ProgressBarLabelPlacement.CENTER; progressBar.width = width; progressBar.label = getProgress(); progressBar.setProgress(value,maximum); silder.x = 0; silder.y = 10; silder.minimum = minimum; silder.maximum = maximum; silder.width = width; silder.snapInterval = snapInterval; silder.value = value; silder.addEventListener(SliderEvent.CHANGE,doSilderChange); addChild(progressBar); addChild(silder); } private function doSilderChange(e : SliderEvent) : void { progressBar.setProgress(e.value, maximum); progressBar.label = getProgress(); _value = e.value; dispatchEvent(new Event("change")); } private function getProgress() : String { return Math.ceil(silder.value / maximum * 100) + "%"; } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth,unscaledHeight); silder.width = width; progressBar.width = width; } } }