/src/com/bit101/components/HUISlider.as

https://bitbucket.org/HopeSky/mars_nd2d · ActionScript · 97 lines · 30 code · 14 blank · 53 comment · 0 complexity · e2dfb2b8cbae6514f7abdaf2b970c73b MD5 · raw file

  1. /**
  2. * HUISlider.as
  3. * Keith Peters
  4. * version 0.9.2
  5. *
  6. * A Horizontal slider with a label and a value label.
  7. *
  8. * Copyright (c) 2010 Keith Peters
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a copy
  11. * of this software and associated documentation files (the "Software"), to deal
  12. * in the Software without restriction, including without limitation the rights
  13. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. * copies of the Software, and to permit persons to whom the Software is
  15. * furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included in
  18. * all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. * THE SOFTWARE.
  27. */
  28. package com.bit101.components
  29. {
  30. import flash.display.DisplayObjectContainer;
  31. import flash.events.Event;
  32. public class HUISlider extends UISlider
  33. {
  34. /**
  35. * Constructor
  36. * @param parent The parent DisplayObjectContainer on which to add this HUISlider.
  37. * @param xpos The x position to place this component.
  38. * @param ypos The y position to place this component.
  39. * @param label The string to use as the label for this component.
  40. * @param defaultHandler The event handling function to handle the default event for this component.
  41. */
  42. public function HUISlider(parent:DisplayObjectContainer = null, x:Number = 0, y:Number = 0, label:String = "", defaultEventHandler:Function = null)
  43. {
  44. _sliderClass = HSlider;
  45. super(parent, x, y, label, defaultEventHandler);
  46. }
  47. /**
  48. * Initializes the component.
  49. */
  50. override protected function init():void
  51. {
  52. super.init();
  53. setSize(200, 18);
  54. }
  55. /**
  56. * Centers the label when label text is changed.
  57. */
  58. override protected function positionLabel():void
  59. {
  60. _valueLabel.x = _slider.x + _slider.width + 5;
  61. }
  62. ///////////////////////////////////
  63. // public methods
  64. ///////////////////////////////////
  65. /**
  66. * Draws the visual ui of this component.
  67. */
  68. override public function draw():void
  69. {
  70. super.draw();
  71. _slider.x = _label.width + 5;
  72. _slider.y = height / 2 - _slider.height / 2;
  73. _slider.width = width - _label.width - 50 - 10;
  74. _valueLabel.x = _slider.x + _slider.width + 5;
  75. }
  76. ///////////////////////////////////
  77. // event handlers
  78. ///////////////////////////////////
  79. ///////////////////////////////////
  80. // getter/setters
  81. ///////////////////////////////////
  82. }
  83. }