PageRenderTime 106ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/ActionScript Project/MusicPlayer for RealLife/src/flas/containers/ScrollPane.as

http://abellee87.googlecode.com/
ActionScript | 905 lines | 290 code | 65 blank | 550 comment | 39 complexity | 9d931098eb606751cf4bd654d0945c67 MD5 | raw file
  1. // Copyright 2007. Adobe Systems Incorporated. All Rights Reserved.
  2. package fl.containers {
  3. import fl.containers.BaseScrollPane;
  4. import fl.controls.ScrollBar;
  5. import fl.controls.ScrollPolicy;
  6. import fl.core.InvalidationType;
  7. import fl.core.UIComponent;
  8. import fl.events.ScrollEvent;
  9. import fl.managers.IFocusManagerComponent;
  10. import flash.display.DisplayObject;
  11. import flash.display.Loader;
  12. import flash.display.Sprite;
  13. import flash.events.Event;
  14. import flash.events.KeyboardEvent;
  15. import flash.events.MouseEvent;
  16. import flash.events.ProgressEvent;
  17. import flash.events.SecurityErrorEvent;
  18. import flash.events.IOErrorEvent;
  19. import flash.events.HTTPStatusEvent;
  20. import flash.geom.Rectangle;
  21. import flash.net.URLRequest;
  22. import flash.system.ApplicationDomain;
  23. import flash.system.LoaderContext;
  24. import flash.ui.Keyboard;
  25. //--------------------------------------
  26. // Events
  27. //--------------------------------------
  28. /**
  29. * @copy BaseScrollPane#event:scroll
  30. *
  31. * @includeExample examples/ScrollPane.scroll.1.as -noswf
  32. *
  33. * @eventType fl.events.ScrollEvent.SCROLL
  34. *
  35. * @langversion 3.0
  36. * @playerversion Flash 9.0.28.0
  37. *
  38. * @playerversion AIR 1.0
  39. * @productversion Flash CS3
  40. */
  41. [Event(name="scroll", type="fl.events.ScrollEvent")]
  42. /**
  43. * Dispatched while content is loading.
  44. *
  45. * @eventType flash.events.ProgressEvent.PROGRESS
  46. *
  47. * @includeExample examples/ScrollPane.percentLoaded.1.as -noswf
  48. *
  49. * @see #event:complete
  50. * @see #bytesLoaded
  51. * @see #bytesTotal
  52. * @see #percentLoaded
  53. *
  54. * @langversion 3.0
  55. * @playerversion Flash 9.0.28.0
  56. *
  57. * @playerversion AIR 1.0
  58. * @productversion Flash CS3
  59. */
  60. [Event(name="progress", type="flash.events.ProgressEvent")]
  61. /**
  62. * Dispatched when content has finished loading.
  63. *
  64. * @includeExample examples/ScrollPane.complete.1.as -noswf
  65. *
  66. * @eventType flash.events.Event.COMPLETE
  67. *
  68. * @see #event:progress
  69. *
  70. * @langversion 3.0
  71. * @playerversion Flash 9.0.28.0
  72. *
  73. * @playerversion AIR 1.0
  74. * @productversion Flash CS3
  75. */
  76. [Event(name="complete", type="flash.events.Event")]
  77. /**
  78. * Dispatched when the properties and methods of a loaded SWF file are accessible.
  79. * The following conditions must exist for this event to be dispatched:
  80. * <ul>
  81. * <li>All the properties and methods that are associated with the loaded object,
  82. * as well as those that are associated with the component, must be accessible.</li>
  83. * <li>The constructors for all child objects must have completed.</li>
  84. * </ul>
  85. *
  86. * @eventType flash.events.Event.INIT
  87. *
  88. * @langversion 3.0
  89. * @playerversion Flash 9.0.28.0
  90. *
  91. * @playerversion AIR 1.0
  92. * @productversion Flash CS3
  93. */
  94. [Event("init", type="flash.events.Event")]
  95. /**
  96. * Dispatched after an input or output error occurs.
  97. *
  98. * @includeExample examples/UILoader.ioError.1.as -noswf
  99. *
  100. * @eventType flash.events.IOErrorEvent.IO_ERROR
  101. *
  102. * @langversion 3.0
  103. * @playerversion Flash 9.0.28.0
  104. *
  105. * @playerversion AIR 1.0
  106. * @productversion Flash CS3
  107. */
  108. [Event("ioError", type="flash.events.IOErrorEvent")]
  109. /**
  110. * Dispatched after a network operation starts.
  111. *
  112. * @eventType flash.events.Event.OPEN
  113. *
  114. * @langversion 3.0
  115. * @playerversion Flash 9.0.28.0
  116. *
  117. * @playerversion AIR 1.0
  118. * @productversion Flash CS3
  119. */
  120. [Event("open", type="flash.events.Event")]
  121. /**
  122. * Dispatched after a security error occurs while content is loading.
  123. *
  124. * @eventType flash.events.SecurityErrorEvent.SECURITY_ERROR
  125. *
  126. * @langversion 3.0
  127. * @playerversion Flash 9.0.28.0
  128. *
  129. * @playerversion AIR 1.0
  130. * @productversion Flash CS3
  131. */
  132. [Event("securityError", type="flash.events.SecurityErrorEvent")]
  133. //--------------------------------------
  134. // Styles
  135. //--------------------------------------
  136. /**
  137. * The skin that shows when the scroll pane is disabled.
  138. *
  139. * @default ScrollPane_disabledSkin
  140. *
  141. * @langversion 3.0
  142. * @playerversion Flash 9.0.28.0
  143. *
  144. * @playerversion AIR 1.0
  145. * @productversion Flash CS3
  146. */
  147. [Style(name="disabledSkin", type="Class")]
  148. /**
  149. * The default skin shown on the scroll pane.
  150. *
  151. * @default ScrollPane_upSkin
  152. *
  153. * @langversion 3.0
  154. * @playerversion Flash 9.0.28.0
  155. *
  156. * @playerversion AIR 1.0
  157. * @productversion Flash CS3
  158. */
  159. [Style(name="upSkin", type="Class")]
  160. /**
  161. * The amount of padding to put around the content in the scroll pane, in pixels.
  162. *
  163. * @default 0
  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="contentPadding", type="Number", format="Length")]
  172. //--------------------------------------
  173. // Class description
  174. //--------------------------------------
  175. /**
  176. * The ScrollPane component displays display objects and JPEG, GIF, and PNG files,
  177. * as well as SWF files, in a scrollable area. You can use a scroll pane to
  178. * limit the screen area that is occupied by these media types.
  179. * The scroll pane can display content that is loaded from a local
  180. * disk or from the Internet. You can set this content while
  181. * authoring and, at run time, by using ActionScript. After the scroll
  182. * pane has focus, if its content has valid tab stops, those
  183. * markers receive focus. After the last tab stop in the content,
  184. * focus moves to the next component. The vertical and horizontal
  185. * scroll bars in the scroll pane do not receive focus.
  186. *
  187. * <p><strong>Note:</strong> When content is being loaded from a different
  188. * domain or <em>sandbox</em>, the properties of the content may be inaccessible
  189. * for security reasons. For more information about how domain security
  190. * affects the load process, see the Loader class.</p>
  191. *
  192. * <p><strong>Note:</strong> When loading very large image files into a ScrollPane object,
  193. * it may be necessary to listen for the <code>complete</code> event and then resize the
  194. * ScrollPane using the <code>setSize()</code> method. See the <code>complete</code>
  195. * event example.</p>
  196. *
  197. * @see flash.display.Loader Loader
  198. *
  199. * @includeExample examples/ScrollPaneExample.as -noswf
  200. *
  201. * @langversion 3.0
  202. * @playerversion Flash 9.0.28.0
  203. *
  204. * @playerversion AIR 1.0
  205. * @productversion Flash CS3
  206. */
  207. public class ScrollPane extends BaseScrollPane implements IFocusManagerComponent {
  208. /**
  209. * @private (protected)
  210. *
  211. * @langversion 3.0
  212. * @playerversion Flash 9.0.28.0
  213. */
  214. protected var _source:Object = "";
  215. /**
  216. * @private (protected)
  217. *
  218. * @langversion 3.0
  219. * @playerversion Flash 9.0.28.0
  220. */
  221. protected var _scrollDrag:Boolean = false;
  222. /**
  223. * @private (protected)
  224. *
  225. * @langversion 3.0
  226. * @playerversion Flash 9.0.28.0
  227. */
  228. protected var contentClip:Sprite;
  229. /**
  230. * @private (protected)
  231. *
  232. * @langversion 3.0
  233. * @playerversion Flash 9.0.28.0
  234. */
  235. protected var loader:Loader;
  236. /**
  237. * @private (protected)
  238. *
  239. * @langversion 3.0
  240. * @playerversion Flash 9.0.28.0
  241. */
  242. protected var xOffset:Number;
  243. /**
  244. * @private (protected)
  245. *
  246. * @langversion 3.0
  247. * @playerversion Flash 9.0.28.0
  248. */
  249. protected var yOffset:Number;
  250. /**
  251. * @private (protected)
  252. *
  253. * @langversion 3.0
  254. * @playerversion Flash 9.0.28.0
  255. */
  256. protected var scrollDragHPos:Number;
  257. /**
  258. * @private (protected)
  259. *
  260. * @langversion 3.0
  261. * @playerversion Flash 9.0.28.0
  262. */
  263. protected var scrollDragVPos:Number;
  264. /**
  265. * @private (protected)
  266. *
  267. * @langversion 3.0
  268. * @playerversion Flash 9.0.28.0
  269. */
  270. protected var currentContent:Object;
  271. /**
  272. * @private
  273. *
  274. * @langversion 3.0
  275. * @playerversion Flash 9.0.28.0
  276. */
  277. private static var defaultStyles:Object = {
  278. upSkin:"ScrollPane_upSkin",
  279. disabledSkin:"ScrollPane_disabledSkin",
  280. focusRectSkin:null,
  281. focusRectPadding:null,
  282. contentPadding:0
  283. }
  284. /**
  285. * @copy fl.core.UIComponent#getStyleDefinition()
  286. *
  287. * @includeExample ../core/examples/UIComponent.getStyleDefinition.1.as -noswf
  288. *
  289. * @see fl.core.UIComponent#getStyle() UIComponent.getStyle()
  290. * @see fl.core.UIComponent#setStyle() UIComponent.setStyle()
  291. * @see fl.managers.StyleManager StyleManager
  292. *
  293. * @langversion 3.0
  294. * @playerversion Flash 9.0.28.0
  295. *
  296. * @playerversion AIR 1.0
  297. * @productversion Flash CS3
  298. */
  299. public static function getStyleDefinition():Object {
  300. return mergeStyles(defaultStyles, BaseScrollPane.getStyleDefinition());
  301. }
  302. /**
  303. * Creates a new ScrollPane component instance.
  304. *
  305. * @langversion 3.0
  306. * @playerversion Flash 9.0.28.0
  307. *
  308. * @playerversion AIR 1.0
  309. * @productversion Flash CS3
  310. */
  311. public function ScrollPane() {
  312. super();
  313. }
  314. [Inspectable(type="Boolean", defaultValue="false")]
  315. /**
  316. * Gets or sets a value that indicates whether scrolling occurs when a
  317. * user drags on content within the scroll pane. A value of <code>true</code>
  318. * indicates that scrolling occurs when a user drags on the content; a value
  319. * of <code>false</code> indicates that it does not.
  320. *
  321. * @default false
  322. *
  323. * @includeExample examples/ScrollPane.scrollDrag.1.as -noswf
  324. *
  325. * @see #event:scroll
  326. *
  327. * @langversion 3.0
  328. * @playerversion Flash 9.0.28.0
  329. *
  330. * @playerversion AIR 1.0
  331. * @productversion Flash CS3
  332. */
  333. public function get scrollDrag():Boolean {
  334. return _scrollDrag;
  335. }
  336. /**
  337. * @private (setter)
  338. *
  339. * @langversion 3.0
  340. * @playerversion Flash 9.0.28.0
  341. */
  342. public function set scrollDrag(value:Boolean):void {
  343. _scrollDrag = value;
  344. invalidate(InvalidationType.STATE);
  345. }
  346. /**
  347. * Gets a number between 0 and 100 indicating what percentage of the content is loaded.
  348. * If you are loading assets from your library, and not externally loaded content,
  349. * the <code>percentLoaded</code> property is set to 0.
  350. *
  351. * @default 0
  352. *
  353. * @includeExample examples/ScrollPane.percentLoaded.1.as -noswf
  354. *
  355. * @see #bytesLoaded
  356. * @see #bytesTotal
  357. *
  358. * @langversion 3.0
  359. * @playerversion Flash 9.0.28.0
  360. *
  361. * @playerversion AIR 1.0
  362. * @productversion Flash CS3
  363. */
  364. public function get percentLoaded():Number {
  365. if (loader != null) {
  366. return Math.round((bytesLoaded / bytesTotal) * 100);
  367. } else {
  368. return 0;
  369. }
  370. }
  371. /**
  372. * Gets the count of bytes of content that have been loaded.
  373. * When this property equals the value of <code>bytesTotal</code>,
  374. * all the bytes are loaded.
  375. *
  376. * @default 0
  377. *
  378. * @see #bytesTotal
  379. * @see #percentLoaded
  380. *
  381. * @includeExample examples/ScrollPane.bytesLoaded.1.as -noswf
  382. *
  383. * @langversion 3.0
  384. * @playerversion Flash 9.0.28.0
  385. *
  386. * @playerversion AIR 1.0
  387. * @productversion Flash CS3
  388. */
  389. public function get bytesLoaded():Number {
  390. return (loader == null || loader.contentLoaderInfo == null) ? 0 : loader.contentLoaderInfo.bytesLoaded;
  391. }
  392. /**
  393. * Gets the count of bytes of content to be loaded.
  394. *
  395. * @default 0
  396. *
  397. * @includeExample examples/ScrollPane.percentLoaded.1.as -noswf
  398. *
  399. * @see #bytesLoaded
  400. * @see #percentLoaded
  401. *
  402. * @langversion 3.0
  403. * @playerversion Flash 9.0.28.0
  404. *
  405. * @playerversion AIR 1.0
  406. * @productversion Flash CS3
  407. */
  408. public function get bytesTotal():Number {
  409. return (loader == null || loader.contentLoaderInfo == null) ? 0 : loader.contentLoaderInfo.bytesTotal;
  410. }
  411. /**
  412. * Reloads the contents of the scroll pane.
  413. *
  414. * <p> This method does not redraw the scroll bar. To reset the
  415. * scroll bar, use the <code>update()</code> method.</p>
  416. *
  417. * @includeExample examples/ScrollPane.refreshPane.1.as -noswf
  418. *
  419. * @see #update()
  420. *
  421. * @langversion 3.0
  422. * @playerversion Flash 9.0.28.0
  423. *
  424. * @playerversion AIR 1.0
  425. * @productversion Flash CS3
  426. */
  427. public function refreshPane():void {
  428. if (_source is URLRequest) {
  429. _source = _source.url;
  430. }
  431. source = _source;
  432. }
  433. /**
  434. * Refreshes the scroll bar properties based on the width
  435. * and height of the content. This is useful if the content
  436. * of the ScrollPane changes during run time.
  437. *
  438. * @includeExample examples/ScrollPane.update.1.as -noswf
  439. *
  440. * @see #refreshPane()
  441. *
  442. * @langversion 3.0
  443. * @playerversion Flash 9.0.28.0
  444. *
  445. * @playerversion AIR 1.0
  446. * @productversion Flash CS3
  447. */
  448. public function update():void {
  449. var child:DisplayObject = contentClip.getChildAt(0);
  450. setContentSize(child.width, child.height);
  451. }
  452. /**
  453. * Gets a reference to the content loaded into the scroll pane.
  454. *
  455. * @default null
  456. *
  457. * @includeExample examples/ScrollPane.content.1.as -noswf
  458. * @includeExample examples/ScrollPane.content.2.as -noswf
  459. *
  460. * @langversion 3.0
  461. * @playerversion Flash 9.0.28.0
  462. *
  463. * @playerversion AIR 1.0
  464. * @productversion Flash CS3
  465. */
  466. public function get content():DisplayObject {
  467. var c:Object = currentContent;
  468. if (c is URLRequest) {
  469. c = loader.content;
  470. }
  471. return c as DisplayObject;
  472. }
  473. [Inspectable(type="String", defaultValue="")]
  474. /**
  475. * Gets or sets an absolute or relative URL that identifies the
  476. * location of the SWF or image file to load, the class name
  477. * of a movie clip in the library, a reference to a display object,
  478. * or a instance name of a movie clip on the same level as the component.
  479. *
  480. * <p>Valid image file formats include GIF, PNG, and JPEG. To load an
  481. * asset by using a URLRequest object, use the <code>load()</code>
  482. * method.</p>
  483. *
  484. * @default null
  485. *
  486. * @includeExample examples/ScrollPane.source.1.as -noswf
  487. * @includeExample examples/ScrollPane.source.2.as -noswf
  488. *
  489. * @see #load()
  490. *
  491. * @langversion 3.0
  492. * @playerversion Flash 9.0.28.0
  493. *
  494. * @playerversion AIR 1.0
  495. * @productversion Flash CS3
  496. */
  497. public function get source():Object {
  498. return _source;
  499. }
  500. /**
  501. * @private (setter)
  502. *
  503. * @langversion 3.0
  504. * @playerversion Flash 9.0.28.0
  505. */
  506. public function set source(value:Object):void {
  507. clearContent();
  508. if (isLivePreview) { return; }
  509. _source = value;
  510. if (_source == "" || _source == null) {
  511. return;
  512. }
  513. currentContent = getDisplayObjectInstance(value);
  514. if (currentContent != null) {
  515. var child = contentClip.addChild(currentContent as DisplayObject);
  516. dispatchEvent(new Event(Event.INIT));
  517. update();
  518. } else {
  519. load(new URLRequest(_source.toString()));
  520. }
  521. }
  522. /**
  523. * The request parameter of this method accepts only a URLRequest object
  524. * whose <code>source</code> property contains a string, a class, or a
  525. * URLRequest object.
  526. *
  527. * By default, the LoaderContext object uses the current domain as the
  528. * application domain. To specify a different application domain value,
  529. * to check a policy file, or to change the security domain, initialize
  530. * a new LoaderContext object and pass it to this method.
  531. *
  532. * @param request The URLRequest object to use to load an image into the scroll pane.
  533. * @param context The LoaderContext object that sets the context of the load operation.
  534. *
  535. * @see #source
  536. * @see fl.containers.UILoader#load() UILoader.load()
  537. * @see flash.net.URLRequest
  538. * @see flash.system.ApplicationDomain
  539. * @see flash.system.LoaderContext
  540. *
  541. * @includeExample examples/ScrollPane.load.1.as -noswf
  542. *
  543. * @langversion 3.0
  544. * @playerversion Flash 9.0.28.0
  545. *
  546. * @playerversion AIR 1.0
  547. * @productversion Flash CS3
  548. */
  549. public function load(request:URLRequest, context:LoaderContext=null):void {
  550. if (context == null) {
  551. context = new LoaderContext(false, ApplicationDomain.currentDomain);
  552. }
  553. clearContent();
  554. initLoader();
  555. currentContent = _source = request;
  556. loader.load(request, context);
  557. }
  558. /**
  559. * @private (protected)
  560. *
  561. * @langversion 3.0
  562. * @playerversion Flash 9.0.28.0
  563. */
  564. override protected function setVerticalScrollPosition(scrollPos:Number, fireEvent:Boolean=false):void {
  565. var contentScrollRect = contentClip.scrollRect;
  566. contentScrollRect.y = scrollPos;
  567. contentClip.scrollRect = contentScrollRect;
  568. }
  569. /**
  570. * @private (protected)
  571. *
  572. * @langversion 3.0
  573. * @playerversion Flash 9.0.28.0
  574. */
  575. override protected function setHorizontalScrollPosition(scrollPos:Number, fireEvent:Boolean=false):void {
  576. var contentScrollRect = contentClip.scrollRect;
  577. contentScrollRect.x = scrollPos;
  578. contentClip.scrollRect = contentScrollRect;
  579. }
  580. /**
  581. * @private (protected)
  582. */
  583. override protected function drawLayout():void {
  584. super.drawLayout();
  585. contentScrollRect = contentClip.scrollRect;
  586. contentScrollRect.width = availableWidth;
  587. contentScrollRect.height = availableHeight;
  588. contentClip.cacheAsBitmap = useBitmapScrolling;
  589. contentClip.scrollRect = contentScrollRect;
  590. contentClip.x = contentClip.y = contentPadding;
  591. }
  592. /**
  593. * @private (protected)
  594. *
  595. * @langversion 3.0
  596. * @playerversion Flash 9.0.28.0
  597. */
  598. protected function onContentLoad(event:Event):void {
  599. update();
  600. //Need to reset the sizes, for scrolling purposes.
  601. //Just reset the scrollbars, don't redraw the entire pane.
  602. var availableHeight = calculateAvailableHeight();
  603. calculateAvailableSize();
  604. horizontalScrollBar.setScrollProperties(availableWidth, 0, (useFixedHorizontalScrolling) ? _maxHorizontalScrollPosition : contentWidth - availableWidth, availableWidth);
  605. verticalScrollBar.setScrollProperties(availableHeight, 0, contentHeight - availableHeight, availableHeight);
  606. passEvent(event);
  607. }
  608. /**
  609. * @private (protected)
  610. *
  611. * @langversion 3.0
  612. * @playerversion Flash 9.0.28.0
  613. */
  614. protected function passEvent(event:Event):void {
  615. dispatchEvent(event);
  616. }
  617. /**
  618. * @private (protected)
  619. *
  620. * @langversion 3.0
  621. * @playerversion Flash 9.0.28.0
  622. */
  623. protected function initLoader():void {
  624. loader = new Loader();
  625. loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,handleError,false,0,true);
  626. loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,handleError,false,0,true);
  627. loader.contentLoaderInfo.addEventListener(Event.OPEN,passEvent,false,0,true);
  628. loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,passEvent,false,0,true);
  629. loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onContentLoad,false,0,true);
  630. loader.contentLoaderInfo.addEventListener(Event.INIT,passEvent,false,0,true);
  631. loader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS,passEvent,false,0,true);
  632. contentClip.addChild(loader);
  633. }
  634. /**
  635. * @private (protected)
  636. *
  637. * @langversion 3.0
  638. * @playerversion Flash 9.0.28.0
  639. */
  640. override protected function handleScroll(event:ScrollEvent):void {
  641. passEvent(event);
  642. super.handleScroll(event);
  643. }
  644. /**
  645. * @private (protected)
  646. *
  647. * @langversion 3.0
  648. * @playerversion Flash 9.0.28.0
  649. */
  650. protected function handleError(event:Event):void {
  651. passEvent(event);
  652. clearLoadEvents();
  653. loader.contentLoaderInfo.removeEventListener(Event.INIT,handleInit);
  654. }
  655. /**
  656. * @private (protected)
  657. *
  658. * @langversion 3.0
  659. * @playerversion Flash 9.0.28.0
  660. */
  661. protected function handleInit(event:Event):void {
  662. loader.contentLoaderInfo.removeEventListener(Event.INIT,handleInit);
  663. passEvent(event);
  664. invalidate(InvalidationType.SIZE);
  665. }
  666. /**
  667. * @private (protected)
  668. *
  669. * @langversion 3.0
  670. * @playerversion Flash 9.0.28.0
  671. */
  672. protected function clearLoadEvents():void {
  673. loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,handleError);
  674. loader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR,handleError);
  675. loader.contentLoaderInfo.removeEventListener(Event.OPEN,passEvent);
  676. loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,passEvent);
  677. loader.contentLoaderInfo.removeEventListener(HTTPStatusEvent.HTTP_STATUS,passEvent);
  678. loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,onContentLoad);
  679. }
  680. /**
  681. * @private (protected)
  682. *
  683. * @langversion 3.0
  684. * @playerversion Flash 9.0.28.0
  685. */
  686. protected function doDrag(event:MouseEvent):void {
  687. var yPos = scrollDragVPos-(mouseY-yOffset);
  688. _verticalScrollBar.setScrollPosition(yPos);
  689. setVerticalScrollPosition(_verticalScrollBar.scrollPosition,true);
  690. var xPos = scrollDragHPos-(mouseX-xOffset);
  691. _horizontalScrollBar.setScrollPosition(xPos);
  692. setHorizontalScrollPosition(_horizontalScrollBar.scrollPosition,true);
  693. }
  694. /**
  695. * @private (protected)
  696. *
  697. * @langversion 3.0
  698. * @playerversion Flash 9.0.28.0
  699. */
  700. protected function doStartDrag(event:MouseEvent):void {
  701. if (!enabled) { return; }
  702. xOffset = mouseX;
  703. yOffset = mouseY;
  704. scrollDragHPos = horizontalScrollPosition;
  705. scrollDragVPos = verticalScrollPosition;
  706. stage.addEventListener(MouseEvent.MOUSE_MOVE, doDrag, false, 0, true);
  707. }
  708. /**
  709. * @private (protected)
  710. *
  711. * @langversion 3.0
  712. * @playerversion Flash 9.0.28.0
  713. */
  714. protected function endDrag(event:MouseEvent):void {
  715. stage.removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
  716. }
  717. /**
  718. * @private (protected)
  719. *
  720. * @langversion 3.0
  721. * @playerversion Flash 9.0.28.0
  722. */
  723. protected function setScrollDrag():void {
  724. if (_scrollDrag) {
  725. contentClip.addEventListener(MouseEvent.MOUSE_DOWN, doStartDrag, false, 0, true);
  726. stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, false, 0, true);
  727. } else {
  728. contentClip.removeEventListener(MouseEvent.MOUSE_DOWN, doStartDrag);
  729. stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
  730. removeEventListener(MouseEvent.MOUSE_MOVE, doDrag);
  731. }
  732. contentClip.buttonMode = _scrollDrag;
  733. }
  734. /**
  735. * @private (protected)
  736. *
  737. * @langversion 3.0
  738. * @playerversion Flash 9.0.28.0
  739. */
  740. override protected function draw():void {
  741. if (isInvalid(InvalidationType.STYLES)) {
  742. drawBackground();
  743. }
  744. if (isInvalid(InvalidationType.STATE)) {
  745. setScrollDrag();
  746. }
  747. super.draw();
  748. }
  749. /**
  750. * @private (protected)
  751. *
  752. * @langversion 3.0
  753. * @playerversion Flash 9.0.28.0
  754. */
  755. override protected function drawBackground():void {
  756. var bg:DisplayObject = background;
  757. background = getDisplayObjectInstance(getStyleValue(enabled ? "upSkin" : "disabledSkin"));
  758. background.width = width;
  759. background.height = height;
  760. addChildAt(background,0);
  761. if (bg != null && bg != background) { removeChild(bg); }
  762. }
  763. /**
  764. * @private (protected)
  765. *
  766. * @langversion 3.0
  767. * @playerversion Flash 9.0.28.0
  768. */
  769. protected function clearContent():void {
  770. if (contentClip.numChildren == 0) { return; }
  771. contentClip.removeChildAt(0);
  772. currentContent = null;
  773. if (loader != null) {
  774. try {
  775. loader.close();
  776. } catch (e:*) {}
  777. try {
  778. loader.unload();
  779. } catch (e:*) {}
  780. loader = null;
  781. }
  782. }
  783. /**
  784. * @private
  785. *
  786. * @langversion 3.0
  787. * @playerversion Flash 9.0.28.0
  788. */
  789. override protected function keyDownHandler(event:KeyboardEvent):void {
  790. var pageSize:int = calculateAvailableHeight();
  791. switch (event.keyCode) {
  792. case Keyboard.DOWN:
  793. verticalScrollPosition++;
  794. break;
  795. case Keyboard.UP:
  796. verticalScrollPosition--;
  797. break;
  798. case Keyboard.RIGHT:
  799. horizontalScrollPosition++;
  800. break;
  801. case Keyboard.LEFT:
  802. horizontalScrollPosition--;
  803. break;
  804. case Keyboard.END:
  805. verticalScrollPosition = maxVerticalScrollPosition;
  806. break;
  807. case Keyboard.HOME:
  808. verticalScrollPosition = 0;
  809. break;
  810. case Keyboard.PAGE_UP:
  811. verticalScrollPosition -= pageSize;
  812. break;
  813. case Keyboard.PAGE_DOWN:
  814. verticalScrollPosition += pageSize;
  815. break;
  816. }
  817. }
  818. /**
  819. * @private
  820. */
  821. protected function calculateAvailableHeight():Number {
  822. var pad:Number = Number(getStyleValue("contentPadding"));
  823. return height-pad*2-((_horizontalScrollPolicy == ScrollPolicy.ON || (_horizontalScrollPolicy == ScrollPolicy.AUTO && _maxHorizontalScrollPosition > 0)) ? 15 : 0);
  824. }
  825. /**
  826. * @private (protected)
  827. *
  828. * @langversion 3.0
  829. * @playerversion Flash 9.0.28.0
  830. */
  831. override protected function configUI():void {
  832. super.configUI();
  833. contentClip = new Sprite();
  834. addChild(contentClip);
  835. contentClip.scrollRect = contentScrollRect;
  836. _horizontalScrollPolicy = ScrollPolicy.AUTO;
  837. _verticalScrollPolicy = ScrollPolicy.AUTO;
  838. }
  839. }
  840. }