PageRenderTime 47ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/ActionScript Project/MusicPlayer for RealLife/src/flas/controls/LabelButton.as

http://abellee87.googlecode.com/
ActionScript | 879 lines | 242 code | 64 blank | 573 comment | 65 complexity | 1bd5f1fb4801eac5e49503141e1ac003 MD5 | raw file
  1. // Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
  2. package fl.controls {
  3. import fl.controls.BaseButton;
  4. import fl.controls.ButtonLabelPlacement;
  5. import fl.controls.TextInput; //Only for ASDocs
  6. import fl.core.InvalidationType;
  7. import fl.core.UIComponent;
  8. import fl.events.ComponentEvent;
  9. import fl.managers.IFocusManagerComponent;
  10. import flash.events.Event;
  11. import flash.events.KeyboardEvent;
  12. import flash.events.MouseEvent;
  13. import flash.display.DisplayObject;
  14. import flash.display.Sprite;
  15. import flash.geom.Point;
  16. import flash.text.TextField;
  17. import flash.text.TextFieldType;
  18. import flash.text.TextFormat;
  19. import flash.ui.Keyboard;
  20. //--------------------------------------
  21. // Events
  22. //--------------------------------------
  23. /**
  24. * Dispatched after the toggle button receives input from
  25. * a mouse device or from the spacebar.
  26. *
  27. * @eventType flash.events.MouseEvent.CLICK
  28. *
  29. * @includeExample examples/LabelButton.click.1.as -noswf
  30. *
  31. * @langversion 3.0
  32. * @playerversion Flash 9.0.28.0
  33. *
  34. * @playerversion AIR 1.0
  35. * @productversion Flash CS3
  36. */
  37. [Event(name="click", type="flash.events.MouseEvent")]
  38. /**
  39. * Dispatched after the label value changes.
  40. *
  41. * @eventType fl.events.ComponentEvent.LABEL_CHANGE
  42. *
  43. * @includeExample examples/LabelButton.labelChange.1.as -noswf
  44. *
  45. * @langversion 3.0
  46. * @playerversion Flash 9.0.28.0
  47. *
  48. * @playerversion AIR 1.0
  49. * @productversion Flash CS3
  50. */
  51. [Event(name="labelChange", type="fl.events.ComponentEvent")]
  52. //--------------------------------------
  53. // Styles
  54. //--------------------------------------
  55. /**
  56. * Name of the class to use as the skin for the background and border
  57. * when the button is not selected and is disabled.
  58. *
  59. * @default Button_disabledSkin
  60. *
  61. * @langversion 3.0
  62. * @playerversion Flash 9.0.28.0
  63. *
  64. * @playerversion AIR 1.0
  65. * @productversion Flash CS3
  66. */
  67. [Style(name="disabledSkin", type="Class")]
  68. /**
  69. * Name of the class to use as the skin for the background and border
  70. * when the button is not selected and the mouse is not over the component.
  71. *
  72. * @default Button_upSkin
  73. *
  74. * @langversion 3.0
  75. * @playerversion Flash 9.0.28.0
  76. *
  77. * @playerversion AIR 1.0
  78. * @productversion Flash CS3
  79. */
  80. [Style(name="upSkin", type="Class")]
  81. /**
  82. * Name of the class to use as the skin for the background and border
  83. * when the button is not selected and the mouse button is down.
  84. *
  85. * @default Button_downSkin
  86. *
  87. * @langversion 3.0
  88. * @playerversion Flash 9.0.28.0
  89. *
  90. * @playerversion AIR 1.0
  91. * @productversion Flash CS3
  92. */
  93. [Style(name="downSkin", type="Class")]
  94. /**
  95. * Name of the class to use as the skin for the background and border
  96. * when the button is not selected and the mouse is over the component.
  97. *
  98. * @default Button_overSkin
  99. *
  100. * @langversion 3.0
  101. * @playerversion Flash 9.0.28.0
  102. *
  103. * @playerversion AIR 1.0
  104. * @productversion Flash CS3
  105. */
  106. [Style(name="overSkin", type="Class")]
  107. /**
  108. * Name of the class to use as the skin for the background and border
  109. * when a toggle button is selected and disabled.
  110. *
  111. * @default Button_selectedDisabledSkin
  112. *
  113. * @langversion 3.0
  114. * @playerversion Flash 9.0.28.0
  115. *
  116. * @playerversion AIR 1.0
  117. * @productversion Flash CS3
  118. */
  119. [Style(name="selectedDisabledSkin", type="Class")]
  120. /**
  121. * Name of the class to use as the skin for the background and border
  122. * when a toggle button is selected and the mouse is not over the component.
  123. *
  124. * @default Button_selectedUpSkin
  125. *
  126. * @langversion 3.0
  127. * @playerversion Flash 9.0.28.0
  128. *
  129. * @playerversion AIR 1.0
  130. * @productversion Flash CS3
  131. */
  132. [Style(name="selectedUpSkin", type="Class")]
  133. /**
  134. * Name of the class to use as the skin for the background and border
  135. * when a toggle button is selected and the mouse button is down.
  136. *
  137. * @default Button_selectedDownSkin
  138. *
  139. * @langversion 3.0
  140. * @playerversion Flash 9.0.28.0
  141. *
  142. * @playerversion AIR 1.0
  143. * @productversion Flash CS3
  144. */
  145. [Style(name="selectedDownSkin", type="Class")]
  146. /**
  147. * Name of the class to use as the skin for the background and border
  148. * when a toggle button is selected and the mouse is over the component.
  149. *
  150. * @default Button_selectedOverSkin
  151. *
  152. * @langversion 3.0
  153. * @playerversion Flash 9.0.28.0
  154. *
  155. * @playerversion AIR 1.0
  156. * @productversion Flash CS3
  157. */
  158. [Style(name="selectedOverSkin", type="Class")]
  159. /**
  160. * The spacing between the text and the edges of the component, and the
  161. * spacing between the text and the icon, in pixels.
  162. *
  163. * @default 5
  164. *
  165. * @langversion 3.0
  166. * @playerversion Flash 9.0.28.0
  167. *
  168. * @playerversion AIR 1.0
  169. * @productversion Flash CS3
  170. */
  171. [Style(name="textPadding", type="Number", format="Length")]
  172. /**
  173. * @copy fl.controls.BaseButton#style:repeatDelay
  174. *
  175. * @default 500
  176. *
  177. * @langversion 3.0
  178. * @playerversion Flash 9.0.28.0
  179. *
  180. * @playerversion AIR 1.0
  181. * @productversion Flash CS3
  182. */
  183. [Style(name="repeatDelay", type="Number", format="Time")]
  184. /**
  185. * @copy fl.controls.BaseButton#style:repeatInterval
  186. *
  187. * @default 35
  188. *
  189. * @langversion 3.0
  190. * @playerversion Flash 9.0.28.0
  191. *
  192. * @playerversion AIR 1.0
  193. * @productversion Flash CS3
  194. */
  195. [Style(name="repeatInterval", type="Number", format="Time")]
  196. /**
  197. * Name of the class to use as the icon when a toggle button is not selected
  198. * and the mouse is not over the button.
  199. *
  200. * @default null
  201. *
  202. * @langversion 3.0
  203. * @playerversion Flash 9.0.28.0
  204. *
  205. * @playerversion AIR 1.0
  206. * @productversion Flash CS3
  207. */
  208. [Style(name="icon", type="Class")]
  209. /**
  210. * Name of the class to use as the icon when a toggle button is not selected and the mouse is not over the button.
  211. *
  212. * @default null
  213. *
  214. * @langversion 3.0
  215. * @playerversion Flash 9.0.28.0
  216. *
  217. * @playerversion AIR 1.0
  218. * @productversion Flash CS3
  219. */
  220. [Style(name="upIcon", type="Class")]
  221. /**
  222. * Name of the class to use as the icon when the button is not selected and the mouse button is down.
  223. *
  224. * @default null
  225. *
  226. * @langversion 3.0
  227. * @playerversion Flash 9.0.28.0
  228. *
  229. * @playerversion AIR 1.0
  230. * @productversion Flash CS3
  231. */
  232. [Style(name="downIcon", type="Class")]
  233. /**
  234. * Name of the class to use as the icon when the button is not selected and the mouse is over the component.
  235. *
  236. * @default null
  237. *
  238. * @langversion 3.0
  239. * @playerversion Flash 9.0.28.0
  240. *
  241. * @playerversion AIR 1.0
  242. * @productversion Flash CS3
  243. */
  244. [Style(name="overIcon", type="Class")]
  245. /**
  246. * Name of the class to use as the icon when the button is not disabled.
  247. *
  248. * @default null
  249. *
  250. * @langversion 3.0
  251. * @playerversion Flash 9.0.28.0
  252. *
  253. * @playerversion AIR 1.0
  254. * @productversion Flash CS3
  255. */
  256. [Style(name="disabledIcon", type="Class")]
  257. /**
  258. * Name of the class to use as the icon when the button is selected and disabled.
  259. *
  260. * @default null
  261. *
  262. * @langversion 3.0
  263. * @playerversion Flash 9.0.28.0
  264. *
  265. * @playerversion AIR 1.0
  266. * @productversion Flash CS3
  267. */
  268. [Style(name="selectedDisabledIcon", type="Class")]
  269. /**
  270. * Name of the class to use as the icon when the button is selected and the mouse button is up.
  271. *
  272. * @default null
  273. *
  274. * @langversion 3.0
  275. * @playerversion Flash 9.0.28.0
  276. *
  277. * @playerversion AIR 1.0
  278. * @productversion Flash CS3
  279. */
  280. [Style(name="selectedUpIcon", type="Class")]
  281. /**
  282. * Name of the class to use as the icon when the button is selected and the mouse button is down.
  283. *
  284. * @default null
  285. *
  286. * @langversion 3.0
  287. * @playerversion Flash 9.0.28.0
  288. *
  289. * @playerversion AIR 1.0
  290. * @productversion Flash CS3
  291. */
  292. [Style(name="selectedDownIcon", type="Class")]
  293. /**
  294. * Name of the class to use as the icon when the button is selected and the mouse is over the component.
  295. *
  296. * @default null
  297. *
  298. * @langversion 3.0
  299. * @playerversion Flash 9.0.28.0
  300. *
  301. * @playerversion AIR 1.0
  302. * @productversion Flash CS3
  303. */
  304. [Style(name="selectedOverIcon", type="Class")]
  305. /**
  306. * Indicates whether embedded font outlines are used to render the text field.
  307. * If this value is <code>true</code>, Flash Player renders the text field
  308. * by using embedded font outlines. If this value is <code>false</code>,
  309. * Flash Player renders the text field by using device fonts.
  310. *
  311. * <p>If you set the <code>embedFonts</code> property to <code>true</code>
  312. * for a text field, you must specify a font for that text by using the
  313. * <code>font</code> property of a TextFormat object that is applied to the text field.
  314. * If the specified font is not embedded in the SWF file, the text is not displayed.</p>
  315. *
  316. * @default false
  317. *
  318. * @langversion 3.0
  319. * @playerversion Flash 9.0.28.0
  320. *
  321. * @playerversion AIR 1.0
  322. * @productversion Flash CS3
  323. */
  324. [Style(name="embedFonts", type="Boolean")]
  325. //--------------------------------------
  326. // Class description
  327. //--------------------------------------
  328. /**
  329. * The LabelButton class is an abstract class that extends the
  330. * BaseButton class by adding a label, an icon, and toggle functionality.
  331. * The LabelButton class is subclassed by the Button, CheckBox, RadioButton, and
  332. * CellRenderer classes.
  333. *
  334. * <p>The LabelButton component is used as a simple button class that can be
  335. * combined with custom skin states that support ScrollBar buttons, NumericStepper
  336. * buttons, ColorPicker swatches, and so on.</p>
  337. *
  338. * @includeExample examples/LabelButtonExample.as -noswf
  339. * @includeExample examples/IconWithToolTip.as
  340. *
  341. * @see fl.controls.BaseButton
  342. *
  343. * @langversion 3.0
  344. * @playerversion Flash 9.0.28.0
  345. *
  346. * @playerversion AIR 1.0
  347. * @productversion Flash CS3
  348. */
  349. public class LabelButton extends BaseButton implements IFocusManagerComponent {
  350. /**
  351. * A reference to the component's internal text field.
  352. *
  353. * @langversion 3.0
  354. * @playerversion Flash 9.0.28.0
  355. *
  356. * @playerversion AIR 1.0
  357. * @productversion Flash CS3
  358. */
  359. public var textField:TextField;
  360. /**
  361. * @private (protected)
  362. *
  363. * @langversion 3.0
  364. * @playerversion Flash 9.0.28.0
  365. */
  366. protected var _labelPlacement:String = ButtonLabelPlacement.RIGHT;
  367. /**
  368. * @private (protected)
  369. *
  370. * @langversion 3.0
  371. * @playerversion Flash 9.0.28.0
  372. */
  373. protected var _toggle:Boolean = false;
  374. /**
  375. * @private (protected)
  376. *
  377. * @langversion 3.0
  378. * @playerversion Flash 9.0.28.0
  379. */
  380. protected var icon:DisplayObject;
  381. /**
  382. * @private (protected)
  383. *
  384. * @langversion 3.0
  385. * @playerversion Flash 9.0.28.0
  386. */
  387. protected var oldMouseState:String;
  388. /**
  389. * @private (protected)
  390. *
  391. * @langversion 3.0
  392. * @playerversion Flash 9.0.28.0
  393. */
  394. protected var _label:String = "Label";
  395. /**
  396. * @private (protected)
  397. *
  398. * @langversion 3.0
  399. * @playerversion Flash 9.0.28.0
  400. */
  401. protected var mode:String = "center"; // other option is "border". Not currently used, but is reference in subclasses.
  402. /**
  403. * @private
  404. *
  405. * @langversion 3.0
  406. * @playerversion Flash 9.0.28.0
  407. */
  408. private static var defaultStyles:Object = {
  409. icon:null,
  410. upIcon:null,downIcon:null,overIcon:null,disabledIcon:null,
  411. selectedDisabledIcon:null,selectedUpIcon:null,selectedDownIcon:null,selectedOverIcon:null,
  412. textFormat:null, disabledTextFormat:null,
  413. textPadding:5, embedFonts:false
  414. };
  415. /**
  416. * @copy fl.core.UIComponent#getStyleDefinition()
  417. *
  418. * @includeExample ../core/examples/UIComponent.getStyleDefinition.1.as -noswf
  419. *
  420. * @see fl.core.UIComponent#getStyle()
  421. * @see fl.core.UIComponent#setStyle()
  422. * @see fl.managers.StyleManager
  423. *
  424. * @langversion 3.0
  425. * @playerversion Flash 9.0.28.0
  426. *
  427. * @playerversion AIR 1.0
  428. * @productversion Flash CS3
  429. */
  430. public static function getStyleDefinition():Object {
  431. return mergeStyles(defaultStyles, BaseButton.getStyleDefinition());
  432. }
  433. /**
  434. * @private
  435. * Method for creating the Accessibility class.
  436. * This method is called from UIComponent.
  437. *
  438. * @langversion 3.0
  439. * @playerversion Flash 9.0.28.0
  440. */
  441. public static var createAccessibilityImplementation:Function;
  442. /**
  443. * Creates a new LabelButton component instance.
  444. *
  445. * @langversion 3.0
  446. * @playerversion Flash 9.0.28.0
  447. *
  448. * @playerversion AIR 1.0
  449. * @productversion Flash CS3
  450. */
  451. public function LabelButton() {
  452. super();
  453. }
  454. [Inspectable(defaultValue="Label")]
  455. /**
  456. * Gets or sets the text label for the component. By default, the label
  457. * text appears centered on the button.
  458. *
  459. * <p><strong>Note:</strong> Setting this property triggers the <code>labelChange</code>
  460. * event object to be dispatched.</p>
  461. *
  462. * @default "Label"
  463. *
  464. * @see #event:labelChange
  465. *
  466. * @langversion 3.0
  467. * @playerversion Flash 9.0.28.0
  468. *
  469. * @playerversion AIR 1.0
  470. * @productversion Flash CS3
  471. */
  472. public function get label():String {
  473. return _label;
  474. }
  475. /**
  476. * @private (setter)
  477. *
  478. * @langversion 3.0
  479. * @playerversion Flash 9.0.28.0
  480. */
  481. public function set label(value:String):void {
  482. _label = value;
  483. if (textField.text != _label) {
  484. textField.text = _label;
  485. dispatchEvent(new ComponentEvent(ComponentEvent.LABEL_CHANGE));
  486. }
  487. invalidate(InvalidationType.SIZE);
  488. invalidate(InvalidationType.STYLES);
  489. }
  490. [Inspectable(enumeration="left,right,top,bottom", defaultValue="right", name="labelPlacement")]
  491. /**
  492. * Position of the label in relation to a specified icon.
  493. *
  494. * <p>In ActionScript, you can use the following constants to set this property:</p>
  495. *
  496. * <ul>
  497. * <li><code>ButtonLabelPlacement.RIGHT</code></li>
  498. * <li><code>ButtonLabelPlacement.LEFT</code></li>
  499. * <li><code>ButtonLabelPlacement.BOTTOM</code></li>
  500. * <li><code>ButtonLabelPlacement.TOP</code></li>
  501. * </ul>
  502. *
  503. * @default ButtonLabelPlacement.RIGHT
  504. *
  505. * @includeExample examples/LabelButton.labelPlacement.1.as -noswf
  506. *
  507. * @see ButtonLabelPlacement
  508. *
  509. * @langversion 3.0
  510. * @playerversion Flash 9.0.28.0
  511. *
  512. * @playerversion AIR 1.0
  513. * @productversion Flash CS3
  514. */
  515. public function get labelPlacement():String {
  516. return _labelPlacement;
  517. }
  518. /**
  519. * @private (setter)
  520. *
  521. * @langversion 3.0
  522. * @playerversion Flash 9.0.28.0
  523. */
  524. public function set labelPlacement(value:String):void {
  525. _labelPlacement = value;
  526. invalidate(InvalidationType.SIZE);
  527. }
  528. [Inspectable(defaultValue=false)]
  529. /**
  530. * Gets or sets a Boolean value that indicates whether a button
  531. * can be toggled. A value of <code>true</code> indicates that it
  532. * can; a value of <code>false</code> indicates that it cannot.
  533. *
  534. * <p>If this value is <code>true</code>, clicking the button
  535. * toggles it between selected and unselected states. You can get
  536. * or set this state programmatically by using the <code>selected</code>
  537. * property.</p>
  538. *
  539. * <p>If this value is <code>false</code>, the button does not
  540. * stay pressed after the user releases it. In this case, its
  541. * <code>selected</code> property is always <code>false</code>.</p>
  542. *
  543. * <p><strong>Note:</strong> When the <code>toggle</code> is set to <code>false</code>,
  544. * <code>selected</code> is forced to <code>false</code> because only
  545. * toggle buttons can be selected.</p>
  546. *
  547. * @default false
  548. *
  549. * @includeExample examples/LabelButton.toggle.2.as -noswf
  550. *
  551. * @langversion 3.0
  552. * @playerversion Flash 9.0.28.0
  553. *
  554. * @playerversion AIR 1.0
  555. * @productversion Flash CS3
  556. */
  557. public function get toggle():Boolean {
  558. return _toggle;
  559. }
  560. /**
  561. * @private (setter)
  562. *
  563. * @langversion 3.0
  564. * @playerversion Flash 9.0.28.0
  565. */
  566. public function set toggle(value:Boolean):void {
  567. if (!value && super.selected) { selected = false; }
  568. _toggle = value;
  569. if (_toggle) { addEventListener(MouseEvent.CLICK,toggleSelected,false,0,true); }
  570. else { removeEventListener(MouseEvent.CLICK,toggleSelected); }
  571. invalidate(InvalidationType.STATE);
  572. }
  573. /**
  574. * @private (protected)
  575. *
  576. * @langversion 3.0
  577. * @playerversion Flash 9.0.28.0
  578. */
  579. protected function toggleSelected(event:MouseEvent):void {
  580. selected = !selected;
  581. dispatchEvent(new Event(Event.CHANGE, true));
  582. }
  583. [Inspectable(defaultValue=false)]
  584. /**
  585. * Gets or sets a Boolean value that indicates whether
  586. * a toggle button is toggled in the on or off position.
  587. * A value of <code>true</code> indicates that it is
  588. * toggled in the on position; a value of <code>false</code> indicates
  589. * that it is toggled in the off position. This property can be
  590. * set only if the <code>toggle</code> property is set to <code>true</code>.
  591. *
  592. * <p>For a CheckBox component, this value indicates whether the box
  593. * displays a check mark. For a RadioButton component, this value
  594. * indicates whether the component is selected.</p>
  595. *
  596. * <p>The user can change this property by clicking the component,
  597. * but you can also set this property programmatically.</p>
  598. *
  599. * <p>If the <code>toggle</code> property is set to <code>true</code>,
  600. * changing this property also dispatches a <code>change</code> event.</p>
  601. *
  602. * @default false
  603. *
  604. * @includeExample examples/LabelButton.toggle.1.as -noswf
  605. *
  606. * @langversion 3.0
  607. * @playerversion Flash 9.0.28.0
  608. *
  609. * @playerversion AIR 1.0
  610. * @productversion Flash CS3
  611. */
  612. override public function get selected():Boolean {
  613. return (_toggle) ? _selected : false;
  614. }
  615. /**
  616. * @private (setter)
  617. *
  618. * @langversion 3.0
  619. * @playerversion Flash 9.0.28.0
  620. */
  621. override public function set selected(value:Boolean):void {
  622. _selected = value;
  623. if (_toggle) {
  624. invalidate(InvalidationType.STATE);
  625. }
  626. }
  627. /**
  628. * @private (protected)
  629. *
  630. * @langversion 3.0
  631. * @playerversion Flash 9.0.28.0
  632. */
  633. override protected function configUI():void {
  634. super.configUI();
  635. textField = new TextField();
  636. textField.type = TextFieldType.DYNAMIC;
  637. textField.selectable = false;
  638. addChild(textField);
  639. }
  640. /**
  641. * @private (protected)
  642. *
  643. * @langversion 3.0
  644. * @playerversion Flash 9.0.28.0
  645. */
  646. override protected function draw():void {
  647. if (textField.text != _label) {
  648. label = _label;
  649. }
  650. if (isInvalid(InvalidationType.STYLES,InvalidationType.STATE)) {
  651. drawBackground();
  652. drawIcon();
  653. drawTextFormat();
  654. invalidate(InvalidationType.SIZE,false);
  655. }
  656. if (isInvalid(InvalidationType.SIZE)) {
  657. drawLayout();
  658. }
  659. if (isInvalid(InvalidationType.SIZE,InvalidationType.STYLES)) {
  660. if (isFocused && focusManager.showFocusIndicator) { drawFocus(true); }
  661. }
  662. validate(); // because we're not calling super.draw
  663. }
  664. /**
  665. * @private (protected)
  666. *
  667. * @langversion 3.0
  668. * @playerversion Flash 9.0.28.0
  669. */
  670. protected function drawIcon():void {
  671. var oldIcon:DisplayObject = icon;
  672. var styleName:String = (enabled) ? mouseState : "disabled";
  673. if (selected) {
  674. styleName = "selected"+styleName.substr(0,1).toUpperCase()+styleName.substr(1);
  675. }
  676. styleName += "Icon";
  677. var iconStyle:Object = getStyleValue(styleName);
  678. if (iconStyle == null) {
  679. // try the default icon:
  680. iconStyle = getStyleValue("icon");
  681. }
  682. if (iconStyle != null) {
  683. icon = getDisplayObjectInstance(iconStyle);
  684. }
  685. if (icon != null) {
  686. addChildAt(icon,1);
  687. }
  688. if (oldIcon != null && oldIcon != icon) {
  689. removeChild(oldIcon);
  690. }
  691. }
  692. /**
  693. * @private (protected)
  694. *
  695. * @langversion 3.0
  696. * @playerversion Flash 9.0.28.0
  697. */
  698. protected function drawTextFormat():void {
  699. // Apply a default textformat
  700. var uiStyles:Object = UIComponent.getStyleDefinition();
  701. var defaultTF:TextFormat = enabled ? uiStyles.defaultTextFormat as TextFormat : uiStyles.defaultDisabledTextFormat as TextFormat;
  702. textField.setTextFormat(defaultTF);
  703. var tf:TextFormat = getStyleValue(enabled?"textFormat":"disabledTextFormat") as TextFormat;
  704. if (tf != null) {
  705. textField.setTextFormat(tf);
  706. } else {
  707. tf = defaultTF;
  708. }
  709. textField.defaultTextFormat = tf;
  710. setEmbedFont();
  711. }
  712. /**
  713. * @private (protected)
  714. *
  715. * @langversion 3.0
  716. * @playerversion Flash 9.0.28.0
  717. */
  718. protected function setEmbedFont() {
  719. var embed:Object = getStyleValue("embedFonts");
  720. if (embed != null) {
  721. textField.embedFonts = embed;
  722. }
  723. }
  724. /**
  725. * @private (protected)
  726. *
  727. * @langversion 3.0
  728. * @playerversion Flash 9.0.28.0
  729. */
  730. override protected function drawLayout():void {
  731. var txtPad:Number = Number(getStyleValue("textPadding"));
  732. var placement:String = (icon == null && mode == "center") ? ButtonLabelPlacement.TOP : _labelPlacement;
  733. textField.height = textField.textHeight+4;
  734. var txtW:Number = textField.textWidth+4;
  735. var txtH:Number = textField.textHeight+4;
  736. var paddedIconW:Number = (icon == null) ? 0 : icon.width+txtPad;
  737. var paddedIconH:Number = (icon == null) ? 0 : icon.height+txtPad;
  738. textField.visible = (label.length > 0);
  739. if (icon != null) {
  740. icon.x = Math.round((width-icon.width)/2);
  741. icon.y = Math.round((height-icon.height)/2);
  742. }
  743. var tmpWidth:Number;
  744. var tmpHeight:Number;
  745. if (textField.visible == false) {
  746. textField.width = 0;
  747. textField.height = 0;
  748. } else if (placement == ButtonLabelPlacement.BOTTOM || placement == ButtonLabelPlacement.TOP) {
  749. tmpWidth = Math.max(0,Math.min(txtW,width-2*txtPad));
  750. if (height-2 > txtH) {
  751. tmpHeight = txtH;
  752. } else {
  753. tmpHeight = height-2;
  754. }
  755. textField.width = txtW = tmpWidth;
  756. textField.height = txtH = tmpHeight;
  757. textField.x = Math.round((width-txtW)/2);
  758. textField.y = Math.round((height-textField.height-paddedIconH)/2+((placement == ButtonLabelPlacement.BOTTOM) ? paddedIconH : 0));
  759. if (icon != null) {
  760. icon.y = Math.round((placement == ButtonLabelPlacement.BOTTOM) ? textField.y-paddedIconH : textField.y+textField.height+txtPad);
  761. }
  762. } else {
  763. tmpWidth = Math.max(0,Math.min(txtW,width-paddedIconW-2*txtPad));
  764. textField.width = txtW = tmpWidth;
  765. textField.x = Math.round((width-txtW-paddedIconW)/2+((placement != ButtonLabelPlacement.LEFT) ? paddedIconW : 0));
  766. textField.y = Math.round((height-textField.height)/2);
  767. if (icon != null) {
  768. icon.x = Math.round((placement != ButtonLabelPlacement.LEFT) ? textField.x-paddedIconW : textField.x+txtW+txtPad);
  769. }
  770. }
  771. super.drawLayout();
  772. }
  773. /**
  774. * @private (protected)
  775. *
  776. * @langversion 3.0
  777. * @playerversion Flash 9.0.28.0
  778. */
  779. override protected function keyDownHandler(event:KeyboardEvent):void {
  780. if (!enabled) { return; }
  781. if (event.keyCode == Keyboard.SPACE) {
  782. if(oldMouseState == null) {
  783. oldMouseState = mouseState;
  784. }
  785. setMouseState("down");
  786. startPress();
  787. }
  788. }
  789. /**
  790. * @private (protected)
  791. *
  792. * @langversion 3.0
  793. * @playerversion Flash 9.0.28.0
  794. */
  795. override protected function keyUpHandler(event:KeyboardEvent):void {
  796. if (!enabled) { return; }
  797. if (event.keyCode == Keyboard.SPACE) {
  798. setMouseState(oldMouseState);
  799. oldMouseState = null;
  800. endPress();
  801. dispatchEvent(new MouseEvent(MouseEvent.CLICK));
  802. }
  803. }
  804. /**
  805. * @private (protected)
  806. *
  807. * @langversion 3.0
  808. * @playerversion Flash 9.0.28.0
  809. */
  810. override protected function initializeAccessibility():void {
  811. if (LabelButton.createAccessibilityImplementation != null)
  812. LabelButton.createAccessibilityImplementation(this);
  813. }
  814. }
  815. }