PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/DiegoRay/actionscripts/org/casaframework/load/media/MediaLoad.as

https://github.com/joemaffia/flash-junk
ActionScript | 120 lines | 44 code | 18 blank | 58 comment | 5 complexity | e9ab1f03afd926690c872d787527c6ce MD5 | raw file
  1. /*
  2. CASA Framework for ActionScript 2.0
  3. Copyright (C) 2007 CASA Framework
  4. http://casaframework.org
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. import org.casaframework.load.base.BytesLoad;
  18. import org.casaframework.time.FrameDelay;
  19. /**
  20. Allows the implementation of event observers that provide status information while SWF, JPEG, GIF, and PNG files are being loaded into a MovieClip or level. This is designed to replace <code>loadMovie()</code>.
  21. Advantages over MovieClipLoader &amp; <code>loadMovie</code>:
  22. <ul>
  23. <li>Includes {@link RetryableLoad#setLoadRetries} and {@link BytesLoad#setLoadTimeout}.</li>
  24. <li>Sends load events using {@link EventDispatcher}.</li>
  25. <li>Does not immediatly start loading on definition. Load can be started at anytime with {@link Load#start}.</li>
  26. <li>Built in {@link Load#stop} which ends a current load or unloads a completed load.</li>
  27. <li>Option to hide content until file has completely loaded.</li>
  28. </ul>
  29. @author Aaron Clinger
  30. @version 01/26/07
  31. @since Flash Player 7
  32. @example
  33. <code>
  34. this.createEmptyMovieClip("loadZone_mc", this.getNextHighestDepth());
  35. function onImageLoadProgress(sender:MediaLoad, bytesLoaded:Number, bytesTotal:Number):Void {
  36. trace(bytesLoaded + "/" + bytesTotal + " bytes have been loaded into " + sender.getMovieClip());
  37. }
  38. var mediaLoad:MediaLoad = new MediaLoad(this.loadZone_mc, "test.jpg");
  39. this.mediaLoad.addEventObserver(this, MediaLoad.EVENT_LOAD_PROGRESS, "onImageLoadProgress");
  40. this.mediaLoad.start();
  41. </code>
  42. */
  43. class org.casaframework.load.media.MediaLoad extends BytesLoad {
  44. private var $target:MovieClip;
  45. private var $hideLoad:Boolean;
  46. /**
  47. Defines file and location of load triggered by {@link Load#start start}.
  48. @param target_mc: A path to a MovieClip container where the file specified by <code>filePath</code> should be loaded into.
  49. @param filePath: The absolute or relative URL of the SWF, JPEG, GIF, or PNG file to be loaded.
  50. @param hideUntilLoaded: <strong>[optional]</strong> Indicates to hide <code>target_mc</code> and its contents until file has completely loaded <code>true</code>, or to display contents while loading <code>false</code>; defaults to <code>false</code>.
  51. @usageNote Loading of GIF or PNG is only allowed when publishing to Flash Player 8 or greater.
  52. */
  53. public function MediaLoad(target_mc:MovieClip, filePath:String, hideUntilLoaded:Boolean) {
  54. super(target_mc, filePath);
  55. this.$hideLoad = (hideUntilLoaded != undefined) ? hideUntilLoaded : false;
  56. this.$setClassDescription('org.casaframework.load.media.MediaLoad');
  57. }
  58. /**
  59. @return Returns MovieClip specified in {@link #MediaLoad}.
  60. */
  61. public function getMovieClip():MovieClip {
  62. return this.$target;
  63. }
  64. public function destroy():Void {
  65. delete this.$hideLoad;
  66. super.destroy();
  67. }
  68. private function $startLoad():Void {
  69. if (this.$target.getBytesLoaded() > 4) {
  70. this.$stopLoad();
  71. this.$isLoading = true;
  72. this.$frameDelay = new FrameDelay(this, '$startLoad');
  73. this.$frameDelay.start();
  74. return;
  75. }
  76. super.$startLoad();
  77. this.$target.loadMovie(this.getFilePath());
  78. }
  79. private function $stopLoad():Void {
  80. super.$stopLoad();
  81. this.$target.unloadMovie();
  82. }
  83. private function $loadProgress(bytesLoaded:Number, currentTime:Number):Void {
  84. super.$loadProgress(bytesLoaded, currentTime);
  85. if (!this.$isProgressing)
  86. if (this.$hideLoad)
  87. this.$target._visible = false;
  88. }
  89. private function $onComplete():Void {
  90. super.$onComplete();
  91. if (this.$hideLoad)
  92. this.$target._visible = true;
  93. }
  94. }