用于加载和预加载外部闪存或图像的公共类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于加载和预加载外部闪存或图像的公共类相关的知识,希望对你有一定的参考价值。

See also: http://code.google.com/p/undolibrary/
  1. /**
  2. * Common class for loading an external flash or image
  3. *
  4. * @class UndoLoader
  5. * @author Giovambattista Fazioli <[email protected]>
  6. * @web http://www.undolog.com
  7. * @version 1.0
  8. *
  9. */
  10. import flash.display.*;
  11. import flash.events.*;
  12. import flash.text.*;
  13. import flash.net.*;
  14. import flash.system.*;
  15. //
  16. public class UndoLoader extends MovieClip {
  17. private var _preloader:Preloader;
  18. private var _loader:Loader;
  19. private var _bar:MovieClip;
  20. private var _perc:TextField;
  21.  
  22. /**
  23. * Class constructor
  24. *
  25. * @param void
  26. * @return void
  27. */
  28. public function UndoLoader() {
  29. stage.scaleMode = StageScaleMode.NO_SCALE
  30. stage.align = StageAlign.TOP_LEFT;
  31. addEventListener( Event.ADDED_TO_STAGE, init );
  32. }
  33.  
  34. /**
  35. * Init bar and content. Trigged when added to stage
  36. *
  37. * @param {event} e Passed from addEventListener(). Can be null
  38. * @return void
  39. * @private
  40. */
  41. private function init(e:Event = null):void {
  42. initBar();
  43. loadContent();
  44. }
  45.  
  46. /**
  47. * Create the preloader movie and init it.
  48. *
  49. * @param void
  50. * @return void
  51. * @private
  52. */
  53. private function initBar():void {
  54. _preloader = new Preloader();
  55. _bar = _preloader.bar;
  56. _bar.scaleX = 0;
  57. _perc = _preloader.perc;
  58. _perc.text = '0%';
  59. _preloader.x = (stage.stageWidth - _preloader.width)/2;
  60. _preloader.y = (stage.stageHeight - _preloader.height)/2;
  61. addChild( _preloader );
  62. }
  63.  
  64. /**
  65. * Creare a Loader() object and init PROGRESS and COMPLETE event
  66. *
  67. * @param void
  68. * @return void
  69. * @private
  70. */
  71. private function loadContent():void {
  72. _loader = new Loader();
  73. _loader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, inProgress );
  74. _loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete );
  75. _loader.load( new URLRequest( this.loaderInfo.parameters.filename ) );
  76. addChild( _loader );
  77. }
  78.  
  79. /**
  80. * Trigged when loading in progress. Move the progress bar and set
  81. * the text string
  82. *
  83. * @param {ProgressEvent} e ProgressEvent
  84. * @return void
  85. * @private
  86. */
  87. private function inProgress(e:ProgressEvent = null):void {
  88. var p:Number = Math.floor( (e.bytesLoaded / e.bytesTotal)*100 );
  89. _perc.text = p + '%';
  90. _bar.scaleX = p/100;
  91. }
  92.  
  93. /**
  94. * Trigged when loading is finished. Remove the preloader movie
  95. * from the stage. Get the framerate from loaded movie and set
  96. * framerate to main movie.
  97. *
  98. * @param {Event} e Event
  99. * @return void
  100. * @private
  101. */
  102. private function onComplete(e:Event = null):void {
  103. stage.frameRate = _loader.contentLoaderInfo.frameRate;
  104. removeChild( _preloader );
  105. }
  106. }

以上是关于用于加载和预加载外部闪存或图像的公共类的主要内容,如果未能解决你的问题,请参考以下文章

将外部 xml 文件导入闪存

STM32 从外部闪存引导,QUADSPI 引导加载程序

懒加载和预加载

加载外部数据时闪存 CS4 IDE 内部缓存

图片懒加载和预加载

如何将动态加载的图像调整为闪存(as3)