PageRenderTime 184ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/flexlib/baseClasses/SliderBase.as

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