PageRenderTime 72ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/library/src/flexlib/baseClasses/SliderBase.as

https://github.com/Houssi/flexlib
ActionScript | 1770 lines | 699 code | 272 blank | 799 comment | 97 complexity | 47d275267fe3d8924660bb921b4ab00d MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2004-2007 Adobe Systems Incorporated
  5. // All Rights Reserved.
  6. //
  7. // NOTICE: Adobe permits you to use, modify, and distribute this file
  8. // in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. package flexlib.baseClasses
  12. {
  13. import flexlib.controls.sliderClasses.SliderThumb;
  14. import flash.display.DisplayObject;
  15. import flash.display.Graphics;
  16. import flash.display.Sprite;
  17. import flash.events.Event;
  18. import flash.events.FocusEvent;
  19. import flash.events.KeyboardEvent;
  20. import flash.events.MouseEvent;
  21. import flash.geom.Point;
  22. import flash.utils.getTimer;
  23. import mx.controls.sliderClasses.SliderDataTip;
  24. import mx.controls.sliderClasses.SliderDirection;
  25. import mx.controls.sliderClasses.SliderLabel;
  26. import mx.core.FlexVersion;
  27. import mx.core.IFlexDisplayObject;
  28. import mx.core.mx_internal;
  29. import mx.core.UIComponent;
  30. import mx.effects.Tween;
  31. import mx.events.FlexEvent;
  32. import mx.events.SliderEvent;
  33. import mx.events.SliderEventClickTarget;
  34. import mx.formatters.NumberFormatter;
  35. import mx.managers.ISystemManager;
  36. import mx.managers.SystemManager;
  37. import mx.styles.ISimpleStyleClient;
  38. import mx.styles.StyleProxy;
  39. use namespace mx_internal;
  40. //--------------------------------------
  41. // Events
  42. //--------------------------------------
  43. /**
  44. * Dispatched when the slider changes value due to mouse or keyboard interaction.
  45. *
  46. * <p>If the <code>liveDragging</code> property is <code>true</code>,
  47. * the event is dispatched continuously as the user moves the thumb.
  48. * If <code>liveDragging</code> is <code>false</code>,
  49. * the event is dispatched when the user releases the slider thumb.</p>
  50. *
  51. * @eventType mx.events.SliderEvent.CHANGE
  52. */
  53. [Event(name="change", type="mx.events.SliderEvent")]
  54. /**
  55. * Dispatched when the slider's thumb is pressed and then moved by the mouse.
  56. * This event is always preceded by a <code>thumbPress</code> event.
  57. * @eventType mx.events.SliderEvent.THUMB_DRAG
  58. */
  59. [Event(name="thumbDrag", type="mx.events.SliderEvent")]
  60. /**
  61. * Dispatched when the slider's thumb is pressed, meaning
  62. * the user presses the mouse button over the thumb.
  63. *
  64. * @eventType mx.events.SliderEvent.THUMB_PRESS
  65. */
  66. [Event(name="thumbPress", type="mx.events.SliderEvent")]
  67. /**
  68. * Dispatched when the slider's thumb is released,
  69. * meaning the user releases the mouse button after
  70. * a <code>thumbPress</code> event.
  71. *
  72. * @eventType mx.events.SliderEvent.THUMB_RELEASE
  73. */
  74. [Event(name="thumbRelease", type="mx.events.SliderEvent")]
  75. //--------------------------------------
  76. // Styles
  77. //--------------------------------------
  78. //include "../../styles/metadata/FillStyles.as";
  79. /**
  80. * The color of the black section of the border.
  81. *
  82. * @default 0x919999
  83. */
  84. [Style(name="borderColor", type="uint", format="Color", inherit="no")]
  85. /**
  86. * Invert the direction of the thumbs.
  87. * If <code>true</code>, the thumbs will be flipped.
  88. *
  89. * @default false
  90. */
  91. [Style(name="invertThumbDirection", type="Boolean", inherit="no")]
  92. /**
  93. * The y-position offset (if direction is horizontal)
  94. * or x-position offset (if direction is vertical)
  95. * of the labels relative to the track.
  96. *
  97. * @default -10
  98. */
  99. [Style(name="labelOffset", type="Number", format="Length", inherit="no")]
  100. /**
  101. * The name of the style to use for the slider label.
  102. *
  103. * @default undefined
  104. */
  105. [Style(name="labelStyleName", type="String", inherit="no")]
  106. /**
  107. * Duration in milliseconds for the sliding animation
  108. * when you click on the track to move a thumb.
  109. *
  110. * @default 300
  111. */
  112. [Style(name="slideDuration", type="Number", format="Time", inherit="no")]
  113. /**
  114. * Tweening function used by the sliding animation
  115. * when you click on the track to move a thumb.
  116. *
  117. * @default undefined
  118. */
  119. [Style(name="slideEasingFunction", type="Function", inherit="no")]
  120. /**
  121. * The y-position offset (if direction is horizontal)
  122. * or x-position offset (if direction is vertical)
  123. * of the thumb relative to the track.
  124. *
  125. * @default 0
  126. */
  127. [Style(name="thumbOffset", type="Number", format="Length", inherit="no")]
  128. /**
  129. * The color of the tick marks.
  130. * Can be a hex color value or the string name of a known color.
  131. *
  132. * @default 0x6F7777.
  133. */
  134. [Style(name="tickColor", type="uint", format="Color", inherit="no")]
  135. /**
  136. * The length in pixels of the tick marks.
  137. * If <code>direction</code> is <code>Direction.HORIZONTAL</code>,
  138. * then adjust the height of the tick marks.
  139. * If <code>direction</code> is <code>Direction.VERTICAL</code>,
  140. * then adjust the width.
  141. *
  142. * @default 3
  143. */
  144. [Style(name="tickLength", type="Number", format="Length", inherit="no")]
  145. /**
  146. * The y-position offset (if direction is horizontal)
  147. * or x-position offset (if direction is vertical)
  148. * of the tick marks relative to the track.
  149. *
  150. * @default -6
  151. */
  152. [Style(name="tickOffset", type="Number", format="Length", inherit="no")]
  153. /**
  154. * The thickness in pixels of the tick marks.
  155. * If direction is horizontal,
  156. * then adjust the width of the tick marks.
  157. * If direction is vertical,
  158. * then adjust the height.
  159. *
  160. * @default 1
  161. */
  162. [Style(name="tickThickness", type="Number", format="Length", inherit="no")]
  163. /**
  164. * The colors of the track, as an array of two colors.
  165. * You can use the same color twice for a solid track color.
  166. *
  167. * <p>You use this property along with the <code>fillAlphas</code>
  168. * property. Typically you set <code>fillAlphas</code> to [ 1.0, 1.0 ]
  169. * when setting <code>trackColors</code>.</p>
  170. *
  171. * @default [ 0xE7E7E7, 0xE7E7E7 ]
  172. */
  173. [Style(name="trackColors", type="Array", arrayType="uint", format="Color", inherit="no")]
  174. /**
  175. * Specifies whether to enable track highlighting between thumbs
  176. * (or a single thumb and the beginning of the track).
  177. *
  178. * @default false
  179. */
  180. [Style(name="showTrackHighlight", type="Boolean", inherit="no")]
  181. /**
  182. * The size of the track margins, in pixels.
  183. * If <code>undefined</code>, then the track margins will be determined
  184. * by the length of the first and last labels.
  185. * If given a value, Flex attempts to fit the labels in the available space.
  186. *
  187. * @default undefined
  188. */
  189. [Style(name="trackMargin", type="Number", format="Length", inherit="no")]
  190. /**
  191. * The name of the style declaration to use for the data tip.
  192. *
  193. * @default undefined
  194. */
  195. [Style(name="dataTipStyleName", type="String", inherit="no")]
  196. /**
  197. * The offset, in pixels, of the data tip relative to the thumb.
  198. * Used in combination with the <code>dataTipPlacement</code>
  199. * style property of the HSlider and VSlider controls.
  200. *
  201. * @default 16
  202. */
  203. [Style(name="dataTipOffset", type="Number", format="Length", inherit="no")]
  204. /**
  205. * Number of decimal places to use for the data tip text.
  206. * A value of 0 means to round all values to an integer.
  207. *
  208. * @default 2
  209. */
  210. [Style(name="dataTipPrecision", type="int", inherit="no")]
  211. /**
  212. * The default skin for the slider thumb.
  213. *
  214. * @default SliderThumbSkin
  215. */
  216. [Style(name="thumbSkin", type="Class", inherit="no", states="up, over, down, disabled")]
  217. /**
  218. * The skin for the slider thumb up state.
  219. *
  220. * @default SliderThumbSkin
  221. */
  222. [Style(name="thumbUpSkin", type="Class", inherit="no")]
  223. /**
  224. * The skin for the slider thumb over state.
  225. *
  226. * @default SliderThumbSkin
  227. */
  228. [Style(name="thumbOverSkin", type="Class", inherit="no")]
  229. /**
  230. * The skin for the slider thumb down state.
  231. *
  232. * @default SliderThumbSkin
  233. */
  234. [Style(name="thumbDownSkin", type="Class", inherit="no")]
  235. /**
  236. * The skin for the slider thumb disabled state.
  237. *
  238. * @default SliderThumbSkin
  239. */
  240. [Style(name="thumbDisabledSkin", type="Class", inherit="no")]
  241. /**
  242. * The skin for the slider track when it is selected.
  243. */
  244. [Style(name="trackHighlightSkin", type="Class", inherit="no")]
  245. /**
  246. * The skin for the slider track.
  247. */
  248. [Style(name="trackSkin", type="Class", inherit="no")]
  249. //--------------------------------------
  250. // Other metadata
  251. //--------------------------------------
  252. [AccessibilityClass(implementation="mx.accessibility.SliderAccImpl")]
  253. [ResourceBundle("SharedResources")]
  254. /**
  255. * SliderBase is a copy/paste version of the original Slider class in the Flex framework.
  256. *
  257. * <p>The only modifications made to this class were to change some properties and
  258. * methods from private to protected so we can override them in a subclass.</p>
  259. *
  260. * The Slider class is the base class for the Flex slider controls.
  261. * The slider controls let users select a value by moving a slider thumb
  262. * between the end points of the slider
  263. * track. The current value of the slider is determined by
  264. * the relative location of the thumb between the
  265. * end points of the slider, corresponding to the slider's minimum and maximum values.
  266. * The Slider class is subclassed by HSlider and VSlider.
  267. *
  268. * @mxml
  269. *
  270. * <p>The Slider class cannot be used as an MXML tag. Use the <code>&lt;mx:HSlider&gt;</code>
  271. * and <code>&lt;mx:VSlider&gt;</code> tags instead. However, the Slider class does define tag
  272. * attributes used by the <code>&lt;mx:HSlider&gt;</code> and <code>&lt;mx:VSlider&gt;</code> tags. </p>
  273. *
  274. * <p>The Slider class inherits all of the tag attributes
  275. * of its superclass, and adds the following tag attributes:</p>
  276. *
  277. * <pre>
  278. * &lt;mx:<i>tagname</i>
  279. * <strong>Properties</strong>
  280. * allowThumbOverlap="false|true"
  281. * allowTrackClick="true|false"
  282. * dataTipFormatFunction="undefined"
  283. * direction="horizontal|vertical"
  284. * labels="undefined"
  285. * liveDragging="false|true"
  286. * maximum="10"
  287. * minimum="0"
  288. * showDataTip="true|false"
  289. * sliderDataTipClass="sliderDataTip"
  290. * sliderThumbClass="SliderThumb"
  291. * snapInterval="0"
  292. * thumbCount="1"
  293. * tickInterval="0"
  294. * tickValues="undefined"
  295. * value="<i>The value of the minimum property.</i>"
  296. *
  297. * <strong>Styles</strong>
  298. * borderColor="0x919999"
  299. * dataTipOffset="16"
  300. * dataTipPrecision="2"
  301. * dataTipStyleName="undefined"
  302. * fillAlphas="[0.6, 0.4, 0.75, 0.65]"
  303. * fillColors="[0xFFFFFF, 0xCCCCCC, 0xFFFFFF, 0xEEEEEE;]"
  304. * labelOffset="-10"
  305. * labelStyleName="undefined"
  306. * showTrackHighlight="false"
  307. * slideDuration="300"
  308. * slideEasingFunction="undefined"
  309. * thumbDisabledSkin="SliderThumbSkin"
  310. * thumbDownSkin="SliderThumbSkin"
  311. * thumbOffset="0"
  312. * thumbOverSkin="SliderThumbSkin"
  313. * thumbUpSkin="SliderThumbSkin"
  314. * tickColor="0x6F7777"
  315. * tickLength="3"
  316. * tickOffset="-6"
  317. * tickThickness="1"
  318. * trackColors="[ 0xEEEEEE, 0xFFFFFF ]"
  319. * tracHighlightSkin="SliderHighlightSkin"
  320. * trackMargin="undefined"
  321. * trackSkin="SliderTrackSkin"
  322. *
  323. * <strong>Events</strong>
  324. * change="<i>No default</i>"
  325. * thumbDrag="<i>No default</i>"
  326. * thumbPress="<i>No default</i>"
  327. * thumbRelease="<i>No default</i>"
  328. * /&gt;
  329. * </pre>
  330. */
  331. public class SliderBase extends UIComponent
  332. {
  333. //include "../../core/Version.as";
  334. //--------------------------------------------------------------------------
  335. //
  336. // Class mixins
  337. //
  338. //--------------------------------------------------------------------------
  339. /**
  340. * @private
  341. * Placeholder for mixin by SliderAccImpl.
  342. */
  343. mx_internal static var createAccessibilityImplementation:Function;
  344. //--------------------------------------------------------------------------
  345. //
  346. // Constructor
  347. //
  348. //--------------------------------------------------------------------------
  349. /**
  350. * Constructor.
  351. */
  352. public function SliderBase()
  353. {
  354. super();
  355. tabChildren = true;
  356. }
  357. //--------------------------------------------------------------------------
  358. //
  359. // Variables
  360. //
  361. //--------------------------------------------------------------------------
  362. /**
  363. * @private
  364. */
  365. protected var track:IFlexDisplayObject;
  366. /**
  367. * @private
  368. */
  369. protected var thumbs:UIComponent;
  370. /**
  371. * @private
  372. */
  373. private var thumbsChanged:Boolean = true;
  374. /**
  375. * @private
  376. */
  377. private var ticks:UIComponent;
  378. /**
  379. * @private
  380. */
  381. private var ticksChanged:Boolean = false;
  382. /**
  383. * @private
  384. */
  385. private var labelObjects:UIComponent;
  386. /**
  387. * @private
  388. */
  389. protected var highlightTrack:IFlexDisplayObject;
  390. /**
  391. * @private
  392. */
  393. mx_internal var innerSlider:UIComponent;
  394. /**
  395. * @private
  396. */
  397. private var trackHitArea:UIComponent;
  398. /**
  399. * @private
  400. */
  401. mx_internal var dataTip:SliderDataTip;
  402. /**
  403. * @private
  404. */
  405. private var trackHighlightChanged:Boolean = true;
  406. /**
  407. * @private
  408. */
  409. private var initValues:Boolean = true; // Always initValues at startup
  410. /**
  411. * @private
  412. */
  413. protected var dataFormatter:NumberFormatter;
  414. /**
  415. * @private
  416. */
  417. protected var interactionClickTarget:String;
  418. /**
  419. * @private
  420. */
  421. private var labelStyleChanged:Boolean = false;
  422. /**
  423. * @private
  424. * is the last interaction from the keyboard?
  425. */
  426. mx_internal var keyInteraction:Boolean = false;
  427. //--------------------------------------------------------------------------
  428. //
  429. // Overridden properties
  430. //
  431. //--------------------------------------------------------------------------
  432. //----------------------------------
  433. // baselinePosition
  434. //----------------------------------
  435. /**
  436. * @private
  437. */
  438. override public function get baselinePosition():Number
  439. {
  440. if (FlexVersion.compatibilityVersion < FlexVersion.VERSION_3_0)
  441. return super.baselinePosition;
  442. if (!validateBaselinePosition())
  443. return NaN;
  444. return int(0.75 * height);
  445. }
  446. //----------------------------------
  447. // enabled
  448. //----------------------------------
  449. /**
  450. * @private
  451. */
  452. private var _enabled:Boolean;
  453. /**
  454. * @private
  455. */
  456. private var enabledChanged:Boolean = false;
  457. [Inspectable(category="General", enumeration="true,false", defaultValue="true")]
  458. /**
  459. * @private
  460. */
  461. override public function get enabled():Boolean
  462. {
  463. return _enabled;
  464. }
  465. /**
  466. * @private
  467. */
  468. override public function set enabled(value:Boolean):void
  469. {
  470. _enabled = value;
  471. enabledChanged = true;
  472. invalidateProperties();
  473. }
  474. /**
  475. * @private
  476. */
  477. private var _tabIndex:Number;
  478. /**
  479. * @private
  480. */
  481. private var tabIndexChanged:Boolean;
  482. /**
  483. * @private
  484. */
  485. override public function set tabIndex(value:int):void
  486. {
  487. super.tabIndex = value;
  488. _tabIndex = value;
  489. tabIndexChanged = true;
  490. invalidateProperties();
  491. }
  492. //--------------------------------------------------------------------------
  493. //
  494. // Properties
  495. //
  496. //--------------------------------------------------------------------------
  497. //----------------------------------
  498. // allowThumbOverlap
  499. //----------------------------------
  500. [Inspectable(defaultValue="false")]
  501. /**
  502. * If set to <code>false</code>, then each thumb can only be moved to the edge of
  503. * the adjacent thumb.
  504. * If <code>true</code>, then each thumb can be moved to any position on the track.
  505. *
  506. * @default false
  507. */
  508. public var allowThumbOverlap:Boolean = false;
  509. //----------------------------------
  510. // allowTrackClick
  511. //----------------------------------
  512. [Inspectable(defaultValue="true")]
  513. /**
  514. * Specifies whether clicking on the track will move the slider thumb.
  515. *
  516. * @default true
  517. */
  518. public var allowTrackClick:Boolean = true;
  519. //----------------------------------
  520. // dataTipFormatFunction
  521. //----------------------------------
  522. /**
  523. * @private
  524. */
  525. protected var _dataTipFormatFunction:Function;
  526. /**
  527. * Callback function that formats the data tip text.
  528. * The function takes a single Number as an argument
  529. * and returns a formatted String.
  530. *
  531. * <p>The function has the following signature:</p>
  532. * <pre>
  533. * funcName(value:Number):String
  534. * </pre>
  535. *
  536. * <p>The following example prefixes the data tip text with a dollar sign and
  537. * formats the text using the <code>dataTipPrecision</code>
  538. * of a Slider Control named 'slide': </p>
  539. *
  540. * <pre>
  541. * import mx.formatters.NumberBase;
  542. * function myDataTipFormatter(value:Number):String {
  543. * var dataFormatter:NumberBase = new NumberBase(".", ",", ".", "");
  544. * return "$ " + dataFormatter.formatPrecision(String(value), slide.getStyle("dataTipPrecision"));
  545. * }
  546. * </pre>
  547. *
  548. * @default undefined
  549. */
  550. public function get dataTipFormatFunction():Function
  551. {
  552. return _dataTipFormatFunction;
  553. }
  554. /**
  555. * @private
  556. */
  557. public function set dataTipFormatFunction(value:Function):void
  558. {
  559. _dataTipFormatFunction = value;
  560. }
  561. //----------------------------------
  562. // direction
  563. //----------------------------------
  564. /**
  565. * @private
  566. */
  567. protected var _direction:String = SliderDirection.HORIZONTAL;
  568. /**
  569. * @private
  570. */
  571. private var directionChanged:Boolean = false;
  572. [Inspectable(defaultValue="horizontal")]
  573. /**
  574. * The orientation of the slider control.
  575. * Valid values in MXML are <code>"horizontal"</code> or <code>"vertical"</code>.
  576. *
  577. * <p>In ActionScript, you use the following constants
  578. * to set this property:
  579. * <code>SliderDirection.VERTICAL</code> and
  580. * <code>SliderDirection.HORIZONTAL</code>.</p>
  581. *
  582. * The HSlider and VSlider controls set this property for you;
  583. * do not set it when using those controls.
  584. *
  585. * @default SliderDirection.HORIZONTAL
  586. * @see mx.controls.sliderClasses.SliderDirection
  587. */
  588. public function get direction():String
  589. {
  590. return _direction;
  591. }
  592. /**
  593. * @private
  594. */
  595. public function set direction(value:String):void
  596. {
  597. _direction = value;
  598. directionChanged = true;
  599. invalidateProperties();
  600. invalidateSize();
  601. invalidateDisplayList();
  602. }
  603. //----------------------------------
  604. // labels
  605. //----------------------------------
  606. /**
  607. * @private
  608. */
  609. private var _labels:Array = [];
  610. /**
  611. * @private
  612. */
  613. private var labelsChanged:Boolean = false;
  614. [Inspectable(category="General", arrayType="String", defaultValue="undefined")]
  615. /**
  616. * An array of strings used for the slider labels.
  617. * Flex positions the labels at the beginning of the track,
  618. * and spaces them evenly between the beginning of the track
  619. * and the end of the track.
  620. *
  621. * <p>For example, if the array contains three items,
  622. * the first item is placed at the beginning of the track,
  623. * the second item in the middle, and the last item
  624. * at the end of the track.</p>
  625. *
  626. * <p>If only one label is specified, it is placed at the
  627. * beginning of the track.
  628. * By default, labels are placed above the tick marks
  629. * (if present) or above the track.
  630. * To align the labels with the tick marks, make sure that
  631. * the number of tick marks is equal to the number of labels.</p>
  632. *
  633. * @default undefined
  634. */
  635. public function get labels():Array
  636. {
  637. return _labels;
  638. }
  639. /**
  640. * @private
  641. */
  642. public function set labels(value:Array):void
  643. {
  644. _labels = value;
  645. labelsChanged = true;
  646. invalidateProperties();
  647. invalidateSize();
  648. invalidateDisplayList();
  649. }
  650. //----------------------------------
  651. // liveDragging
  652. //----------------------------------
  653. [Inspectable(category="General", defaultValue="false")]
  654. /**
  655. * Specifies whether live dragging is enabled for the slider.
  656. * If <code>false</code>, Flex sets the <code>value</code> and
  657. * <code>values</code> properties and dispatches the <code>change</code>
  658. * event when the user stops dragging the slider thumb.
  659. * If <code>true</code>, Flex sets the <code>value</code> and
  660. * <code>values</code> properties and dispatches the <code>change</code>
  661. * event continuously as the user moves the thumb.
  662. *
  663. * @default false
  664. */
  665. public var liveDragging:Boolean = false;
  666. //----------------------------------
  667. // maximum
  668. //----------------------------------
  669. /**
  670. * @private
  671. * Storage for the maximum property.
  672. */
  673. private var _maximum:Number = 10;
  674. [Inspectable(category="General", defaultValue="10")]
  675. /**
  676. * The maximum allowed value on the slider.
  677. *
  678. * @default 10
  679. */
  680. public function get maximum():Number
  681. {
  682. return _maximum;
  683. }
  684. /**
  685. * @private
  686. */
  687. public function set maximum(value:Number):void
  688. {
  689. _maximum = value;
  690. ticksChanged = true;
  691. if (!initValues)
  692. valuesChanged = true;
  693. invalidateProperties();
  694. invalidateDisplayList();
  695. }
  696. //----------------------------------
  697. // minimum
  698. //----------------------------------
  699. /**
  700. * @private
  701. * Storage for the minimum property.
  702. */
  703. private var _minimum:Number = 0;
  704. /**
  705. * @private
  706. */
  707. private var minimumSet:Boolean = false;
  708. [Inspectable(category="General", defaultValue="0")]
  709. /**
  710. * The minimum allowed value on the slider control.
  711. *
  712. * @default 0
  713. */
  714. public function get minimum():Number
  715. {
  716. return _minimum;
  717. }
  718. /**
  719. * @private
  720. */
  721. public function set minimum(value:Number):void
  722. {
  723. _minimum = value;
  724. ticksChanged = true;
  725. if (!initValues)
  726. valuesChanged = true;
  727. invalidateProperties();
  728. invalidateDisplayList();
  729. }
  730. //----------------------------------
  731. // showDataTip
  732. //----------------------------------
  733. [Inspectable(category="General", defaultValue="true")]
  734. /**
  735. * If set to <code>true</code>, show a data tip during user interaction
  736. * containing the current value of the slider.
  737. *
  738. * @default true
  739. */
  740. public var showDataTip:Boolean = true;
  741. //----------------------------------
  742. // sliderThumbClass
  743. //----------------------------------
  744. /**
  745. * @private
  746. */
  747. private var _thumbClass:Class = SliderThumb;
  748. /**
  749. * A reference to the class to use for each thumb.
  750. *
  751. * @default SliderThumb
  752. */
  753. public function get sliderThumbClass():Class
  754. {
  755. return _thumbClass;
  756. }
  757. /**
  758. * @private
  759. */
  760. public function set sliderThumbClass(value:Class):void
  761. {
  762. _thumbClass = value;
  763. thumbsChanged = true;
  764. invalidateProperties();
  765. invalidateDisplayList();
  766. }
  767. //----------------------------------
  768. // sliderDataTipClass
  769. //----------------------------------
  770. /**
  771. * @private
  772. */
  773. private var _sliderDataTipClass:Class = SliderDataTip;
  774. /**
  775. * A reference to the class to use for the data tip.
  776. *
  777. * @default SliderDataTip
  778. */
  779. public function get sliderDataTipClass():Class
  780. {
  781. return _sliderDataTipClass;
  782. }
  783. /**
  784. * @private
  785. */
  786. public function set sliderDataTipClass(value:Class):void
  787. {
  788. _sliderDataTipClass = value;
  789. invalidateProperties();
  790. }
  791. //----------------------------------
  792. // snapInterval
  793. //----------------------------------
  794. /**
  795. * @private
  796. */
  797. private var _snapInterval:Number = 0;
  798. /**
  799. * @private
  800. */
  801. private var snapIntervalPrecision:int = -1;
  802. /**
  803. * @private
  804. */
  805. private var snapIntervalChanged:Boolean = false;
  806. [Inspectable(category="General", defaultValue="0")]
  807. /**
  808. * Specifies the increment value of the slider thumb
  809. * as the user moves the thumb.
  810. * For example, if <code>snapInterval</code> is 2,
  811. * the <code>minimum</code> value is 0,
  812. * and the <code>maximum</code> value is 10,
  813. * the thumb snaps to the values 0, 2, 4, 6, 8, and 10
  814. * as the user move the thumb.
  815. * A value of 0, means that the slider moves continuously
  816. * between the <code>minimum</code> and <code>maximum</code> values.
  817. *
  818. * @default 0
  819. */
  820. public function get snapInterval():Number
  821. {
  822. return _snapInterval;
  823. }
  824. /**
  825. * @private
  826. */
  827. public function set snapInterval(value:Number):void
  828. {
  829. _snapInterval = value;
  830. var parts:Array = (new String(1 + value)).split(".");
  831. if (parts.length == 2)
  832. snapIntervalPrecision = parts[1].length;
  833. else
  834. snapIntervalPrecision = -1;
  835. if (!isNaN(value) && value != 0)
  836. {
  837. snapIntervalChanged = true;
  838. invalidateProperties();
  839. invalidateDisplayList();
  840. }
  841. }
  842. //----------------------------------
  843. // thumbCount
  844. //----------------------------------
  845. /**
  846. * @private
  847. * Storage for the thumbCount property.
  848. */
  849. private var _thumbCount:int = 1;
  850. [Inspectable(category="General", defaultValue="1")]
  851. /**
  852. * The number of thumbs allowed on the slider.
  853. * Possible values are 1 or 2.
  854. * If set to 1, then the <code>value</code> property contains
  855. * the current value of the slider.
  856. * If set to 2, then the <code>values</code> property contains
  857. * an array of values representing the value for each thumb.
  858. *
  859. * @default 1
  860. */
  861. public function get thumbCount():int
  862. {
  863. return _thumbCount;
  864. }
  865. /**
  866. * @private
  867. */
  868. public function set thumbCount(value:int):void
  869. {
  870. var numThumbs:int = (value > 2) ? 2 : value;
  871. numThumbs = value < 1 ? 1 : value;
  872. if (numThumbs != _thumbCount)
  873. {
  874. _thumbCount = numThumbs;
  875. thumbsChanged = true;
  876. initValues = true;
  877. invalidateProperties();
  878. invalidateDisplayList();
  879. }
  880. }
  881. //----------------------------------
  882. // thumbStyleFilters
  883. //----------------------------------
  884. /**
  885. * Set of styles to pass from the Slider to the thumbs.
  886. * @see mx.styles.StyleProxy
  887. */
  888. protected function get thumbStyleFilters():Object
  889. {
  890. return null;
  891. }
  892. //----------------------------------
  893. // tickInterval
  894. //----------------------------------
  895. /**
  896. * @private
  897. */
  898. private var _tickInterval:Number = 0;
  899. [Inspectable(category="General", defaultValue="0")]
  900. /**
  901. * The spacing of the tick marks relative to the <code>maximum</code> value
  902. * of the control.
  903. * Flex displays tick marks whenever you set the <code>tickInterval</code>
  904. * property to a nonzero value.
  905. *
  906. * <p>For example, if <code>tickInterval</code> is 1 and
  907. * <code>maximum</code> is 10, then a tick mark is placed at each
  908. * 1/10th interval along the slider.
  909. * A value of 0 shows no tick marks. If the <code>tickValues</code> property
  910. * is set to a non-empty Array, then this property is ignored.</p>
  911. *
  912. * @default 0
  913. */
  914. public function get tickInterval():Number
  915. {
  916. return _tickInterval;
  917. }
  918. /**
  919. * @private
  920. */
  921. public function set tickInterval(value:Number):void
  922. {
  923. _tickInterval = value;
  924. ticksChanged = true;
  925. invalidateProperties();
  926. invalidateDisplayList();
  927. }
  928. //----------------------------------
  929. // tickValues
  930. //----------------------------------
  931. /**
  932. * @private
  933. */
  934. private var _tickValues:Array = [];
  935. [Inspectable(category="General", defaultValue="undefined", arrayType="Number")]
  936. /**
  937. * The positions of the tick marks on the slider. The positions correspond
  938. * to the values on the slider and should be between
  939. * the <code>minimum</code> and <code>maximum</code> values.
  940. * For example, if the <code>tickValues</code> property
  941. * is [0, 2.5, 7.5, 10] and <code>maximum</code> is 10, then a tick mark is placed
  942. * in the following positions along the slider: the beginning of the slider,
  943. * 1/4 of the way in from the left,
  944. * 3/4 of the way in from the left, and at the end of the slider.
  945. *
  946. * <p>If this property is set to a non-empty Array, then the <code>tickInterval</code> property
  947. * is ignored.</p>
  948. *
  949. * @default undefined
  950. */
  951. public function get tickValues():Array
  952. {
  953. return _tickValues;
  954. }
  955. /**
  956. * @private
  957. */
  958. public function set tickValues(value:Array):void
  959. {
  960. _tickValues = value;
  961. ticksChanged = true;
  962. invalidateProperties();
  963. invalidateDisplayList();
  964. }
  965. //----------------------------------
  966. // value
  967. //----------------------------------
  968. [Bindable("change")]
  969. [Bindable("valueCommit")]
  970. [Inspectable(category="General", defaultValue="undefined")]
  971. /**
  972. * Contains the position of the thumb, and is a number between the
  973. * <code>minimum</code> and <code>maximum</code> properties.
  974. * Use the <code>value</code> property when <code>thumbCount</code> is 1.
  975. * When <code>thumbCount</code> is greater than 1, use the
  976. * <code>values</code> property instead.
  977. * The default value is equal to the minimum property.
  978. */
  979. public function get value():Number
  980. {
  981. return _values[0];
  982. }
  983. /**
  984. * @private
  985. */
  986. public function set value(val:Number):void
  987. {
  988. setValueAt(val, 0, true);
  989. valuesChanged = true;
  990. minimumSet = true;
  991. invalidateProperties();
  992. invalidateDisplayList();
  993. dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
  994. }
  995. //----------------------------------
  996. // values
  997. //----------------------------------
  998. /**
  999. * @private
  1000. */
  1001. private var _values:Array = [0, 0];
  1002. /**
  1003. * @private
  1004. */
  1005. private var valuesChanged:Boolean = false;
  1006. [Bindable("change")]
  1007. [Inspectable(category="General", arrayType="Number")]
  1008. /**
  1009. * An array of values for each thumb when <code>thumbCount</code>
  1010. * is greater than 1.
  1011. */
  1012. public function get values():Array
  1013. {
  1014. return _values;
  1015. }
  1016. /**
  1017. * @private
  1018. */
  1019. public function set values(value:Array):void
  1020. {
  1021. _values = value;
  1022. valuesChanged = true;
  1023. minimumSet = true;
  1024. invalidateProperties();
  1025. invalidateDisplayList();
  1026. }
  1027. //--------------------------------------------------------------------------
  1028. //
  1029. // Overridden methods
  1030. //
  1031. //--------------------------------------------------------------------------
  1032. /**
  1033. * @private
  1034. */
  1035. override protected function initializeAccessibility():void
  1036. {
  1037. if (SliderBase.createAccessibilityImplementation != null)
  1038. SliderBase.createAccessibilityImplementation(this);
  1039. }
  1040. /**
  1041. * @private
  1042. */
  1043. override protected function createChildren():void
  1044. {
  1045. super.createChildren();
  1046. if (!innerSlider)
  1047. {
  1048. innerSlider = new UIComponent();
  1049. UIComponent(innerSlider).tabChildren = true;
  1050. addChild(innerSlider);
  1051. }
  1052. createBackgroundTrack();
  1053. if (!trackHitArea)
  1054. {
  1055. trackHitArea = new UIComponent();
  1056. innerSlider.addChild(trackHitArea); // trackHitArea should always be on top
  1057. trackHitArea.addEventListener(MouseEvent.MOUSE_DOWN,
  1058. track_mouseDownHandler);
  1059. }
  1060. invalidateProperties(); // Force commitProperties to be called on instantiation
  1061. }
  1062. /**
  1063. * @private
  1064. */
  1065. override public function styleChanged(styleProp:String):void
  1066. {
  1067. var anyStyle:Boolean = styleProp == null || styleProp == "styleName";
  1068. super.styleChanged(styleProp);
  1069. if (styleProp == "showTrackHighlight" || anyStyle)
  1070. {
  1071. trackHighlightChanged = true;
  1072. invalidateProperties();
  1073. }
  1074. if (styleProp == "trackHighlightSkin" || anyStyle)
  1075. {
  1076. if (innerSlider && highlightTrack)
  1077. {
  1078. innerSlider.removeChild(DisplayObject(highlightTrack));
  1079. highlightTrack = null;
  1080. }
  1081. trackHighlightChanged = true;
  1082. invalidateProperties();
  1083. }
  1084. if (styleProp == "labelStyleName" || anyStyle)
  1085. {
  1086. labelStyleChanged = true;
  1087. invalidateProperties();
  1088. }
  1089. if (styleProp == "trackMargin" || anyStyle)
  1090. {
  1091. invalidateSize();
  1092. }
  1093. if (styleProp == "trackSkin" || anyStyle)
  1094. {
  1095. if (track)
  1096. {
  1097. innerSlider.removeChild(DisplayObject(track));
  1098. track = null;
  1099. createBackgroundTrack();
  1100. }
  1101. }
  1102. invalidateDisplayList();
  1103. }
  1104. /**
  1105. * @private
  1106. */
  1107. override protected function commitProperties():void
  1108. {
  1109. super.commitProperties();
  1110. var n:int;
  1111. var i:int;
  1112. if (trackHighlightChanged)
  1113. {
  1114. trackHighlightChanged = false;
  1115. if (getStyle("showTrackHighlight"))
  1116. {
  1117. createHighlightTrack();
  1118. }
  1119. else if (highlightTrack)
  1120. {
  1121. innerSlider.removeChild(DisplayObject(highlightTrack));
  1122. highlightTrack = null;
  1123. }
  1124. }
  1125. if (directionChanged)
  1126. {
  1127. directionChanged = false;
  1128. var isHorizontal:Boolean = _direction == SliderDirection.HORIZONTAL;
  1129. if (isHorizontal)
  1130. {
  1131. DisplayObject(innerSlider).rotation = 0;
  1132. }
  1133. else
  1134. {
  1135. DisplayObject(innerSlider).rotation = -90;
  1136. innerSlider.y = unscaledHeight;
  1137. }
  1138. if (labelObjects)
  1139. {
  1140. for (var labelIndex:int = labelObjects.numChildren - 1; labelIndex >= 0; labelIndex--)
  1141. {
  1142. var labelObj:SliderLabel = SliderLabel(
  1143. labelObjects.getChildAt(labelIndex));
  1144. labelObj.rotation = isHorizontal ? 0 : 90;
  1145. }
  1146. }
  1147. }
  1148. if (labelStyleChanged && !labelsChanged)
  1149. {
  1150. labelStyleChanged = false;
  1151. if (labelObjects)
  1152. {
  1153. var labelStyleName:String = getStyle("labelStyleName");
  1154. n = labelObjects.numChildren;
  1155. for (i = 0; i < n; i++)
  1156. {
  1157. ISimpleStyleClient(labelObjects.getChildAt(i)).styleName = labelStyleName;
  1158. }
  1159. }
  1160. }
  1161. if (ticksChanged)
  1162. {
  1163. ticksChanged = false;
  1164. createTicks();
  1165. }
  1166. if (labelsChanged)
  1167. {
  1168. labelsChanged = false;
  1169. createLabels();
  1170. }
  1171. if (thumbsChanged)
  1172. {
  1173. thumbsChanged = false;
  1174. createThumbs();
  1175. }
  1176. if (initValues)
  1177. {
  1178. initValues = false;
  1179. if (!valuesChanged)
  1180. {
  1181. var val:Number = minimum;
  1182. n = _thumbCount;
  1183. for (i = 0; i < n; i++)
  1184. {
  1185. _values[i] = val;
  1186. setValueAt(val, i);
  1187. if (_snapInterval && _snapInterval != 0)
  1188. val += snapInterval;
  1189. else
  1190. val++;
  1191. }
  1192. snapIntervalChanged = false;
  1193. }
  1194. }
  1195. if (snapIntervalChanged)
  1196. {
  1197. snapIntervalChanged = false;
  1198. if (!valuesChanged)
  1199. {
  1200. n = thumbs.numChildren;
  1201. for (i = 0; i < n; i++)
  1202. {
  1203. setValueAt(getValueFromX(SliderThumb(thumbs.getChildAt(i)).xPosition), i);
  1204. }
  1205. }
  1206. }
  1207. if (valuesChanged)
  1208. {
  1209. valuesChanged = false;
  1210. n = _thumbCount;
  1211. for (i = 0; i < n; i++)
  1212. {
  1213. setValueAt(getValueFromX(getXFromValue(Math.min(Math.max(values[i], minimum), maximum))), i);
  1214. }
  1215. }
  1216. if (enabledChanged)
  1217. {
  1218. enabledChanged = false;
  1219. n = thumbs.numChildren;
  1220. for (i = 0; i < n; i++)
  1221. {
  1222. SliderThumb(thumbs.getChildAt(i)).enabled = _enabled;
  1223. }
  1224. n = labelObjects ? labelObjects.numChildren : 0;
  1225. for (i = 0; i < n; i++)
  1226. {
  1227. SliderLabel(labelObjects.getChildAt(i)).enabled = _enabled;
  1228. }
  1229. }
  1230. if (tabIndexChanged)
  1231. {
  1232. tabIndexChanged = false;
  1233. n = thumbs.numChildren;
  1234. for (i = 0; i < n; i++)
  1235. {
  1236. SliderThumb(thumbs.getChildAt(i)).tabIndex = _tabIndex;
  1237. }
  1238. }
  1239. }
  1240. /**
  1241. * Calculates the amount of space that the component takes up.
  1242. * A horizontal slider control calculates its height by examining
  1243. * the position of its labels, tick marks, and thumbs
  1244. * relative to the track.
  1245. * The height of the control is equivalent to the position
  1246. * of the bottom of the lowest element subtracted
  1247. * from the position of the top of the highest element.
  1248. * The width of a horizontal slider control defaults to 250 pixels.
  1249. * For a vertical slider control, the width and the length
  1250. * measurements are reversed.
  1251. */
  1252. override protected function measure():void
  1253. {
  1254. super.measure();
  1255. var isHorizontal:Boolean = (direction == SliderDirection.HORIZONTAL);
  1256. var numLabels:int = labelObjects ? labelObjects.numChildren : 0;
  1257. var trackMargin:Number = getStyle("trackMargin");
  1258. var length:Number = DEFAULT_MEASURED_WIDTH;
  1259. if (!isNaN(trackMargin))
  1260. {
  1261. if (numLabels > 0)
  1262. {
  1263. length += (isHorizontal ?
  1264. SliderLabel(labelObjects.getChildAt(0)).getExplicitOrMeasuredWidth() / 2 :
  1265. SliderLabel(labelObjects.getChildAt(0)).getExplicitOrMeasuredHeight() / 2);
  1266. }
  1267. if (numLabels > 1)
  1268. {
  1269. length += (isHorizontal ?
  1270. SliderLabel(labelObjects.getChildAt(numLabels - 1)).getExplicitOrMeasuredWidth() / 2 :
  1271. SliderLabel(labelObjects.getChildAt(numLabels - 1)).getExplicitOrMeasuredHeight() / 2);
  1272. }
  1273. //length += track.width;
  1274. }
  1275. var bounds:Object = getComponentBounds();
  1276. var thickness:Number = bounds.lower - bounds.upper;
  1277. measuredMinWidth = measuredWidth = isHorizontal ? length : thickness;
  1278. measuredMinHeight = measuredHeight = isHorizontal ? thickness : length;
  1279. }
  1280. /**
  1281. * Positions the elements of the control.
  1282. * The track, thumbs, labels, and tick marks are all positioned
  1283. * and sized by this method.
  1284. * The track is sized based on the length of the labels and on the track margin.
  1285. * If you specify a <code>trackMargin</code>, then the size of the track
  1286. * is equal to the available width minus the <code>trackMargin</code> times 2.
  1287. *
  1288. * <p>Tick marks are spaced at even intervals along the track starting from the beginning of the track. An additional tick mark is placed
  1289. * at the end of the track if one doesn't already exist (if the tick interval isn't a multiple of the maximum value). The tick mark
  1290. * y-position is based on the <code>tickOffset</code>. An offset of 0 places the bottom of the tick at the top of the track. Negative offsets
  1291. * move the ticks upwards while positive offsets move them downward through the track.</p>
  1292. *
  1293. * <p>Labels are positioned at even intervals along the track. The labels are always horizontally centered above their
  1294. * interval position unless the <code>trackMargin</code> setting is too small. If you specify a <code>trackMargin</code>, then the first and last labels will
  1295. * position themselves at the left and right borders of the control. Labels will not crop or resize themselves if they overlap,
  1296. * so be sure to allow enough space for them to fit on the track. The y-position is based on the <code>labelOffset</code> property. An offset of 0
  1297. * places the bottom of the label at the top of the track. Unlike tick marks, the labels can not be positioned to overlap the track.
  1298. * If the offset is a positive number, then the top of the label will be positioned below the bottom of the track.</p>
  1299. *
  1300. * <p>The thumbs are positioned to overlap the track. Their x-position is determined by their value. The y-position is
  1301. * controlled by the <code>thumbOffset</code> property. An offset of 0 places the center of the thumb at the center of the track. A negative
  1302. * offset moves the thumbs upwards while a positive offset moves the thumbs downwards.</p>
  1303. *
  1304. * <p>The placement of the tick marks, labels and thumbs are all independent from each other. They will not attempt to reposition
  1305. * themselves if they overlap.</p>
  1306. *
  1307. * <p>For a vertical slider control, the same rules apply. In the above description, substitute width for height, height for width,
  1308. * left for up or top, right for down or bottom, x-position for y-position, and y-position for x-position.</p>
  1309. *
  1310. * @param unscaledWidth Specifies the width of the component, in pixels,
  1311. * in the component's coordinates, regardless of the value of the
  1312. * <code>scaleX</code> property of the component.
  1313. *
  1314. * @param unscaledHeight Specifies the height of the component, in pixels,
  1315. * in the component's coordinates, regardless of the value of the
  1316. * <code>scaleY</code> property of the component.
  1317. */
  1318. override protected function updateDisplayList(unscaledWidth:Number,
  1319. unscaledHeight:Number):void
  1320. {
  1321. super.updateDisplayList(unscaledWidth, unscaledHeight);
  1322. // graphics.beginFill(0xEEEEEE);
  1323. // graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
  1324. // graphics.endFill();
  1325. var isHorizontal:Boolean = (_direction == SliderDirection.HORIZONTAL);
  1326. var numLabels:int = labelObjects ? labelObjects.numChildren : 0;
  1327. var numThumbs:int = thumbs ? thumbs.numChildren : 0;
  1328. var trackMargin:Number = getStyle("trackMargin");
  1329. var widestThumb:Number = 6;
  1330. if (thumbs == null)
  1331. {
  1332. return;
  1333. }
  1334. var firstThumb:SliderThumb = SliderThumb(thumbs.getChildAt(0));
  1335. if (thumbs && firstThumb)
  1336. widestThumb = firstThumb.getExplicitOrMeasuredWidth();
  1337. var trackLeftOffset:Number = widestThumb / 2; // Enough space for the thumb to rest at the edges
  1338. var trackRightOffset:Number = trackLeftOffset;
  1339. var availSpace:Number;
  1340. var firstLabelSize:Number = 0;
  1341. if (numLabels > 0)
  1342. {
  1343. var firstLabel:SliderLabel =
  1344. SliderLabel(labelObjects.getChildAt(0));
  1345. firstLabelSize = isHorizontal ?
  1346. firstLabel.getExplicitOrMeasuredWidth() :
  1347. firstLabel.getExplicitOrMeasuredHeight();
  1348. }
  1349. var lastLabelSize:Number = 0;
  1350. if (numLabels > 1)
  1351. {
  1352. var lastLabel:SliderLabel =
  1353. SliderLabel(labelObjects.getChildAt(numLabels - 1));
  1354. lastLabelSize = isHorizontal ?
  1355. lastLabel.getExplicitOrMeasuredWidth() :
  1356. lastLabel.getExplicitOrMeasuredHeight();
  1357. }
  1358. if (!isNaN(trackMargin))
  1359. availSpace = trackMargin;
  1360. else
  1361. availSpace = (firstLabelSize + lastLabelSize) / 2;
  1362. if (numLabels > 0)
  1363. {
  1364. if (!isNaN(trackMargin))
  1365. {
  1366. trackLeftOffset = Math.max(trackLeftOffset,
  1367. availSpace / (numLabels > 1 ? 2 : 1));
  1368. }
  1369. else
  1370. {
  1371. trackLeftOffset = Math.max(trackLeftOffset, firstLabelSize / 2);
  1372. }
  1373. }
  1374. else
  1375. {
  1376. trackLeftOffset = Math.max(trackLeftOffset, availSpace / 2);
  1377. }
  1378. var bounds:Object = getComponentBounds();
  1379. //track.x = Math.round(trackLeftOffset);
  1380. var trackY:Number = (((isHorizontal ? unscaledHeight : unscaledWidth) -
  1381. (Number(bounds.lower) - Number(bounds.upper))) / 2) - Number(bounds.upper);
  1382. track.move(Math.round(trackLeftOffset), Math.round(trackY));
  1383. track.setActualSize((isHorizontal ? unscaledWidth : unscaledHeight) - (trackLeftOffset * 2), track.
  1384. height);
  1385. // Layout the thumbs' y positions.
  1386. var tY:Number = track.y +
  1387. (track.height - firstThumb.getExplicitOrMeasuredHeight()) / 2 +
  1388. getStyle("thumbOffset");
  1389. var n:int = _thumbCount;
  1390. for (var i:int = 0; i < n; i++)
  1391. {
  1392. var currentThumb:SliderThumb = SliderThumb(thumbs.getChildAt(i));
  1393. currentThumb.move(currentThumb.x, tY);
  1394. currentThumb.visible = true;
  1395. currentThumb.setActualSize(currentThumb.getExplicitOrMeasuredWidth(),
  1396. currentThumb.getExplicitOrMeasuredHeight());
  1397. }
  1398. var g:Graphics = trackHitArea.graphics;
  1399. var tLength:Number = 0
  1400. if (_tickInterval > 0 || (_tickValues && _tickValues.length > 0))
  1401. tLength = getStyle("tickLength");
  1402. g.clear();
  1403. g.beginFill(0, 0);
  1404. var fullThumbHeight:Number = firstThumb.getExplicitOrMeasuredHeight();
  1405. var halfThumbHeight:Number = (!fullThumbHeight) ? 0 : (fullThumbHeight / 2);
  1406. g.drawRect(track.x,
  1407. track.y - halfThumbHeight - tLength,
  1408. track.width,
  1409. track.height + fullThumbHeight + tLength);
  1410. g.endFill();
  1411. if (_direction != SliderDirection.HORIZONTAL)
  1412. innerSlider.y = unscaledHeight;
  1413. layoutTicks();
  1414. layoutLabels();
  1415. setPosFromValue(); // use the value to position the thumb's x
  1416. drawTrackHighlight();
  1417. }
  1418. //--------------------------------------------------------------------------
  1419. //
  1420. // Methods
  1421. //
  1422. //--------------------------------------------------------------------------
  1423. /**
  1424. * @private
  1425. */
  1426. private function createBackgroundTrack():void
  1427. {
  1428. if (!track)
  1429. {
  1430. var trackSkinClass:Class = getStyle("trackSkin");
  1431. if (trackSkinClass)
  1432. {
  1433. track = new trackSkinClass();
  1434. if (track is ISimpleStyleClient)
  1435. ISimpleStyleClient(track).styleName = this;
  1436. innerSlider.addChildAt(DisplayObject(track), 0);
  1437. }
  1438. }
  1439. }
  1440. /**
  1441. * @private
  1442. */
  1443. private function createHighlightTrack():void
  1444. {
  1445. var showTrackHighlight:Boolean = getStyle("showTrackHighlight");
  1446. if (!highlightTrack && showTrackHighlight)
  1447. {
  1448. var trackHighlightClass:Class =
  1449. getStyle("trackHighlightSkin");
  1450. highlightTrack = new trackHighlightClass();
  1451. if (highlightTrack is ISimpleStyleClient)
  1452. ISimpleStyleClient(highlightTrack).styleName = this;
  1453. innerSlider.addChildAt(DisplayObject(highlightTrack),
  1454. innerSlider.getChildIndex(DisplayObject(track)) + 1);
  1455. }
  1456. }
  1457. /**
  1458. * @private
  1459. */
  1460. private function createThumbs():void
  1461. {
  1462. var n:int;
  1463. var i:int;
  1464. // Delete all thumb children
  1465. if (thumbs)
  1466. {
  1467. n = thumbs.numChildren;
  1468. for (i = n - 1; i >= 0; i--)
  1469. {
  1470. // we don't need to bother to remove the event listeners here
  1471. // they will be removed by the garbage collector automatically
  1472. thumbs.removeChildAt(i);
  1473. }
  1474. }
  1475. else
  1476. {
  1477. thumbs = new UIComponent();
  1478. thumbs.tabChildren = true;
  1479. thumbs.tabEnabled = false;
  1480. innerSlider.addChild(thumbs);
  1481. }
  1482. var thumb:SliderThumb; // We want to force the thumb to be a subclass of SliderThumb
  1483. n = _thumbCount;
  1484. for (i = 0; i < n; i++)
  1485. {
  1486. thumb = SliderThumb(new _thumbClass());
  1487. thumb.owner = this;
  1488. thumb.styleName = new StyleProxy(this, thumbStyleFilters);
  1489. thumb.thumbIndex = i;
  1490. thumb.visible = true;
  1491. thumb.enabled = enabled;
  1492. thumb.upSkinName = "thumbUpSkin";
  1493. thumb.downSkinName = "thumbDownSkin";
  1494. thumb.disabledSkinName = "thumbDisabledSkin";
  1495. thumb.overSkinName = "thumbOverSkin";
  1496. thumb.skinName = "thumbSkin";
  1497. thumbs.addChild(thumb);
  1498. thumb.addEv